WCF IMetadataExchange Error



我已经创建了一个具有以下配置的服务主机。

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="MathServiceLib.MathService" behaviorConfiguration="myMathServiceBehave">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:9001/MathService"/>
            <add baseAddress="net.tcp://localhost:9002/MathService"/>
          </baseAddresses>
        </host>
        <endpoint address="http://localhost:9001/MathService" binding="basicHttpBinding" contract="MathServiceLib.IMathService"/>
        <endpoint address ="net.tcp://localhost:9002/MathService" binding ="netTcpBinding" contract="MathServiceLib.IMathService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <!--<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>-->
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="myMathServiceBehave">
          <!--<serviceMetadata httpGetEnabled="true"/>-->
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

我不想使用serviceMetadata httpGetEnabled="true"属性,而是想使用MEX绑定来创建代理。

现在,当我使用启动服务时

 svcHost = new ServiceHost(typeof(MathServiceLib.MathService));
 svcHost.Open();

我收到以下错误,请帮忙。

在服务MathService实现的约定列表中找不到约定名称"IMetadataExchange"。将ServiceMetadataBehavior直接添加到配置文件或ServiceHost以启用对此约定的支持

根据我的经验,您需要指定

<serviceMetadata httpGetEnabled="true"/>

如果你想使用

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>

以下文章提供了全面的信息和示例:
http://msdn.microsoft.com/en-us/library/ms734765(v=vs.110).aspx
http://www.c-sharpcorner.com/UploadFile/81a718/wcf-service-faqs-part-2/

相关内容

  • 没有找到相关文章

最新更新