简体   繁体   中英

WCF IMetadataExchange Error

I have created a service host with following configuration.

<?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>

I don't want to use serviceMetadata httpGetEnabled="true" property instead I want to use MEX binding for proxy creation.

Now when I start my service using

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

I get following error, please help.

The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service MathService. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.

Based on my experience, you need to specify

<serviceMetadata httpGetEnabled="true"/>

if you want to use

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

The following articles provide comprehensive information and examples:
http://msdn.microsoft.com/en-us/library/ms734765(v=vs.110).aspx
http://www.c-sharpcorner.com/UploadFile/81a718/wcf-service-faqs-part-2/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM