locked
Error in the svcutil.exe for Mex - Cannot obtain Metadata from http://localhost... RRS feed

  • Question

  • I am trying to run the Microsoft sample for "Metadata Publishing". When I try to run the sample code under "\WCFWFCardSpace\WCF\Extensibility\Metadata\WsdlDocumentation\CS". I get an error that "Metadata contains a reference that cannot be resolved: http://localhost/servicemodelsamples/service.svc/mex". So I tried to regenerate the proxy by running svutil.exe for "http://localhost/servicemodelsamples/service.svc/mex". But it failed for the following reason:

    Error: Cannot obtain Metadata from http://localhost/servicemodelsamples/service.svc/mex

    If this is a Windows (R) Communication Foundation service to which you have acce
    ss, please check that you have enabled metadata publishing at the specified addr
    ess.  For help enabling metadata publishing, please refer to the MSDN documentat
    ion at http://go.microsoft.com/fwlink/?LinkId=65455.

    Here is the web.config from the sample:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <system.serviceModel>
      <services>
       <service 
         name="Microsoft.ServiceModel.Samples.CalculatorService"
         behaviorConfiguration="CalculatorServiceBehavior">
        <!-- ICalculator 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>
    
      <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
      <behaviors>
       <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
         <serviceMetadata httpGetEnabled="True"/>
         <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
       </serviceBehaviors>
      </behaviors>
    
     </system.serviceModel>
    
    </configuration>
    

    I even added the base address, but it didn't resolve the problem. What could be wrong?

    FYI, When I tried the following URL on brower:
     http://localhost/servicemodelsamples/service.svc/mex it failed to load anything.

    then, I tried
    http://localhost/servicemodelsamples/service.svc and it worked. But, it gave me the following message:

    To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
    svcutil.exe http://ijecm525nirva.iws.win.ml.com/ServiceModelSamples/service.svc?wsdl 

    ijecm525nirva.iws.win.ml.com is my machine name where IIS is running. Please guid me what changes I have to do to make the sample run.

    Thursday, January 6, 2011 5:10 PM

Answers

  • Kuul,

    This was a tricky one to figure out. The problem is in the configuration file. The service is specified as

    <service
         name="Microsoft.ServiceModel.Samples.CalculatorService"
         behaviorConfiguration="CalculatorServiceBehavior">

    The fully qualified type name is incorrect, it should be "Microsoft.Samples.Metadata.CalculatorService". The service you were creating was not listed in the config file so WCF used the defaults which does not include metadata support. Changing the namespace of your service class should fix the problem.

    Please let me know if you have any further questions.

    Michael Green
    WCF Documentation Team

    • Marked as answer by Yi-Lun Luo Thursday, January 13, 2011 9:34 AM
    Thursday, January 6, 2011 11:43 PM

All replies

  • Can you use the service's address to get the WSDL? the url is of the format "http://.../service.svc?wsdl If the wsdl is opened, check if the service is exposed using basicHttpBinding or wsHttpBinding - if it uses basicHttpBinding this means that your service is not configured properly - check that the service name in the web.config matches the exact namespace and type name of the service.
    Please mark posts as answers/helpful if it answers your question. Senior Consultant on WCF, ASP.NET, Siverlight, and Entity Framework. Author of Microsoft's Official WCF 4 Course. Co-Author of the book "ASP.NET 4 Programmer's Reference" (ISBN 978-0470505458).
    Thursday, January 6, 2011 10:20 PM
  • Kuul,

    This was a tricky one to figure out. The problem is in the configuration file. The service is specified as

    <service
         name="Microsoft.ServiceModel.Samples.CalculatorService"
         behaviorConfiguration="CalculatorServiceBehavior">

    The fully qualified type name is incorrect, it should be "Microsoft.Samples.Metadata.CalculatorService". The service you were creating was not listed in the config file so WCF used the defaults which does not include metadata support. Changing the namespace of your service class should fix the problem.

    Please let me know if you have any further questions.

    Michael Green
    WCF Documentation Team

    • Marked as answer by Yi-Lun Luo Thursday, January 13, 2011 9:34 AM
    Thursday, January 6, 2011 11:43 PM