Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF, The contract name 'IMetadataExchange' could not be found

Tags:

c#

asp.net

iis

wcf

I am simply applying code from this article,

http://msdn.microsoft.com/en-us/library/ms733766(v=vs.110).aspx

I did not change anything but after browsing from IIS I am getting

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

What may be wrong, I did just as the link. I searched for an answer. I can handle by adding

  <behaviors>
      <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

But I do not want to add this because when looking at the link msdn does not add. What is the error?

Here is my config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService">

        <!-- This endpoint is exposed at the base address provided by host:                                        http://localhost/servicemodelsamples/service.svc  -->
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />

        <!-- The mex endpoint is explosed at http://localhost/servicemodelsamples/service.svc/mex -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

</configuration>
like image 553
Omer Avatar asked Feb 12 '23 11:02

Omer


1 Answers

For learning it on your own try deleting the below statement and then check your service again.

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

Finally Web.config file will look like this to complete it.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <!-- This section is optional with the default configuration
        model introduced in .NET Framework 4 -->
      <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="MyServiceTypeBehaviors">

        <!-- This endpoint is exposed at the base address provided by host:                                        http://localhost/servicemodelsamples/service.svc  -->
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />

        <!-- The mex endpoint is exposed at http://localhost/servicemodelsamples/service.svc/mex -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
            <serviceBehaviors>
                <behavior name="MyServiceTypeBehaviors" >
                    <!-- Add the following element to your service behavior configuration. -->
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
  </system.serviceModel>

</configuration>
like image 168
Nandha K Avatar answered Feb 15 '23 01:02

Nandha K