none
WCF Metadata Exception RRS feed

  • Question

  • Hi All,

      I am trying to create a WCF service , which is working fine when the web.config of the WCF service looks like below :

    <?xml version="1.0"?>
    <configuration>
    
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <services>
          <service name = "Service1">
            <host>
              <baseAddresses>
                <add baseAddress =
                     "http://localhost/Service1" />
                </baseAddresses>
            </host>
            <endpoint address = ""
                      binding = "basicHttpBinding"
                      contract = "IService1"/>
            <endpoint address = "mex"
                      binding = "mexHttpBinding"
                      contract = "IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
           <behavior>
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
      
    </configuration>
    


    When i press F5 WCF TestClient opened and its work fine. But when i add BehaviorConfiguration attribute in <service> tag and press F5 its throw exception. Web.config looks like this:

    <?xml version="1.0"?>
    <configuration>
    
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <services>
          <service name = "Service1" behaviorConfiguration="SampleBehavior">
            <host>
              <baseAddresses>
                <add baseAddress =
                     "http://localhost/Service1" />
                </baseAddresses>
            </host>
            <endpoint address = ""
                      binding = "basicHttpBinding"
                      contract = "IService1"/>
            <endpoint address = "mex"
                      binding = "mexHttpBinding"
                      contract = "IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
           <behavior name="SampleBehavior">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
      
    </configuration>
    


    When i run this it throws the following exception :

    Error: Cannot obtain Metadata from http://localhost:49631/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://localhost:49631/Service1.svc    Metadata contains a reference that cannot be resolved: 'http://localhost:49631/Service1.svc'.    Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:49631/Service1.svc.  The client and service bindings may be mismatched.    The remote server returned an error: (415) Unsupported Media Type.HTTP GET Error    URI: http://localhost:49631/Service1.svc    The HTML document does not contain Web service discovery information.

    Please let me know what is the reason behind this exception and how to solve this ?

    Thanks & Regards,

    Joy

     

    Monday, January 13, 2014 9:21 AM

Answers

  • Hello Joy,

    Not sure from the error as usually there is an inner exception that provides more detail.  Also check the eventlog.  Recently there was another post with the same outer exception and it was because the service failed to load all the assemblies.  This is not going to be your situation as the difference is in configuration.

    My guess is the inner exception will provide a clue



    Jeff

    Tuesday, January 14, 2014 11:52 PM
  • Hi,

    >>Error: Cannotobtain Metadata fromhttp://localhost:49631/Service1.svc .............

    From the error, we can see that http://localhost:49631/Service1.svc  , it has nothing to do with the baseaddress in your configure file.

    Are you hosting the service in the IIS?

    If so, please do not add the base addres in the configure file when host in the IIS.

    And please set the <serviceDebug includeExceptionDetailInFaults="true" to get more details information.

    Also please try to enable wcf tracing to find the cause.
    #How to enable the wcf tracing:
    http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx .

    Best Regards,
    Amy Peng




    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, January 15, 2014 6:09 AM
    Moderator

All replies

  • Hello Joy,

    Not sure from the error as usually there is an inner exception that provides more detail.  Also check the eventlog.  Recently there was another post with the same outer exception and it was because the service failed to load all the assemblies.  This is not going to be your situation as the difference is in configuration.

    My guess is the inner exception will provide a clue



    Jeff

    Tuesday, January 14, 2014 11:52 PM
  • Hi,

    >>Error: Cannotobtain Metadata fromhttp://localhost:49631/Service1.svc .............

    From the error, we can see that http://localhost:49631/Service1.svc  , it has nothing to do with the baseaddress in your configure file.

    Are you hosting the service in the IIS?

    If so, please do not add the base addres in the configure file when host in the IIS.

    And please set the <serviceDebug includeExceptionDetailInFaults="true" to get more details information.

    Also please try to enable wcf tracing to find the cause.
    #How to enable the wcf tracing:
    http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx .

    Best Regards,
    Amy Peng




    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, January 15, 2014 6:09 AM
    Moderator