views:

35

answers:

2

I have defined a custom binding in my client and server web.config file, but when I try to connect I get this error, server is running IIS 7

Content Type application/xml; charset=utf-8 was not supported by service http://localhost/contentservice.svc/PairService. The client and service bindings may be mismatched.

Server:

  <system.serviceModel>
  <client>
    <endpoint binding="customBinding"  bindingConfiguration="BinaryBinding" contract="Me.IContentService" name="ContentStagingEndpoint" />
  </client>
  <bindings>
    <customBinding>
      <binding name="BinaryBinding">
        <binaryMessageEncoding/>
        <httpTransport/>
      </binding>
    </customBinding>
  </bindings>
  </system.serviceModel>

Client:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ContentService">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="ContentService" name="Me.ContentService">
      <endpoint address="" binding="customBinding"  bindingConfiguration="BinaryBinding" contract="Contracts.IContentService">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
  </services>
  <bindings>
    <customBinding>
      <binding name="BinaryBinding">
        <binaryMessageEncoding/>
        <httpTransport/>
      </binding>
    </customBinding>
  </bindings>
</system.serviceModel>

and here is the code that initiates the call:

var chan = New WebChannelFactory(Of IContentService)(New Uri("http://localhost/contentservice.svc")).CreateChannel();

chan.PairService();
A: 

Try explicitly setting the message version for both client and server. The Content-Type header for Soap1.1 and Soap1.2 are not the same (1.1 = text/xml, 1.2 = application/xml | application/soap+xml), and if they are missmatched, message processing in WCF fails. Try this:

<binaryMessageEncoding MessageVersion="Soap12" />
jrista
that doesn't work, i get "Unrecognized attribute 'MessageVersion'. Note that attribute names are case-sensitive."I have tried both messageVersion and MessageVersion
Keivan
messageVersion is not available for binaryMessageEncoding, its only available for textMessageEncoding
Keivan
Odd...according to the documentation, it is available: http://msdn.microsoft.com/en-us/library/ms731780.aspx. However, it does list only the WSAddressing alternatives: Soap11WSAddressing10, Soap12WSAddressing10. Have you tried either of those options?
jrista
@Keivan: I did some testing of my own, and it appears the MS documentation is incorrect. MessageVersion is not supported for the binary message encoder. That, combined with the content-type you listed (application/xml), I am left rather confused. I would expect the binary encoder to use a .net specific content type, rather than application/xml. Are you certain that the proper bindings are correctly associated with the client and service endpoints?
jrista
A: 

Found the solution, I had to use ChannelFactory instead of WebChannelFactory

var proxy =  ChannelFactory(Of IContentService).CreateChannel(New EndpointAddress("http://localhost/service.svc"))
Keivan