Search code examples
wcfwcf-configuration

WCF - question about endpoint element under system.serviceModel in config file


While implementing a WCF client endpoint, my config file had the following endpoint entry:

<endpoint address="http://localhost/MyProject/Services/MyService.svc/MyService"
      binding="basicHttpBinding" 
      contract="MyNamespace.IContract" /> 

At this point the service is NOT hosted in IIS. Essentially, I am using Cassini to call through to the app. This configuration works fine. However, if I remove the /Myservice element and my config looks like this:

    <endpoint address="http://localhost/MyProject/Services/MyService.svc"
      binding="basicHttpBinding" 
      contract="MyNamespace.IContract" /> 

I get the following exception:

System.ServiceModel.ProtocolException: Content Type text/xml; charset=utf-8 was not supported by service. The client and service bindings may be mismatched

Why does the second config breaks while the first one works? What's so special about the /MyService part of the url?

Thanks!


Solution

  • I suspect it's a problem with the way you defined the endpoint on the service side. Try this:

      <service
        name="NameOfYourService">
    
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/MyProject/Services/"/>
          </baseAddresses>
        </host>
    
        <endpoint
          address=""
          binding="basicHttpBinding"
          contract="Namespace.Contract" />
    
      </service>