8

I'm trying to use binary message encoding in a WCF service, following the many examples on this site.

On the server I have the binding declared as so:

<customBinding>
    <binding name="binaryHttpBinding">
        <binaryMessageEncoding maxReadPoolSize="4096000" maxSessionSize="4096000" maxWritePoolSize="4096000">
            <readerQuotas maxDepth="32" maxStringContentLength="4096000"
            maxArrayLength="4096000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binaryMessageEncoding>
        <httpTransport maxBufferPoolSize="4096000" maxBufferSize="4096000" maxReceivedMessageSize="4096000"/>
    </binding>
</customBinding>

The service is set to use it (I think):

<service behaviorConfiguration="MyService.ServiceBehavior" name="MyService.ContentUploadService">
    <endpoint
        address=""
        binding="customBinding"
        bindingConfiguration="binaryHttpBinding"
        contract="MyService.IContentUpload"
        name="MyService.ContentUploadService"  />

The client has the same declarations:

<customBinding>
    <binding name="binaryHttpBinding">
        <binaryMessageEncoding maxReadPoolSize="4096000" maxSessionSize="4096000" maxWritePoolSize="4096000">
            <readerQuotas maxDepth="32" maxStringContentLength="4096000"
            maxArrayLength="4096000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binaryMessageEncoding>
        <httpTransport maxBufferPoolSize="4096000" maxBufferSize="4096000" maxReceivedMessageSize="4096000"/>
    </binding>
</customBinding>

And:

<endpoint
    address="http://foo.com/ContentUploadService.svc"
    binding="customBinding"
    bindingConfiguration="binaryHttpBinding"
    contract="MyService.IContentUpload"
    name="MyService.ContentUploadService"/>

The client appears to be working, but the server throws an exception that indicates that the binding is not in place:

Content Type application/soap+msbin1 was sent to a service expecting text/xml; charset=utf-8. The client and service bindings may be mismatched.

Immediately prior to this error in the log file is this one, thrown when trying to open the service host, which must be the cause.

Configuration evaluation context not found.

None of the search links I've tried for this message have been helpful. So, what basic piece am I missing?

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
David
  • 81
  • 2
  • 1
    Is service configuration in web.config? Is System.ServiceModel.dll referenced in your server application? – Ladislav Mrnka May 15 '11 at 19:48
  • Yes and yes. The service works fine if I change the binding to basicHttpBinding (as long as the message size stays < 64K). – David May 15 '11 at 20:25
  • `Configuration evaluation context not found` is usually fired if you use some unknown binding or behaviour configuration which is not registered as extension. Make sure that there is no type in your config. Also make sure that your service/@name is correct - it must be Namespace.ServiceName as defined in .svc file. – Ladislav Mrnka May 15 '11 at 20:39
  • Is any part of the binary message encoding declared somewhere else (outside of System.ServiceModel?). As the service works with a different binding, either I'm declaring it incorrectly or I don't have a needed reference. – David May 15 '11 at 20:41
  • 2
    All of the binary encoding is declared within System.ServiceModel. The problem you're having is due to the service not recognizing the configuration for the service (if no endpoints are declared on the service, you'll get a default one, which happens to use BasicHttpBinding). Are you hosting the service in IIS? Is the web.config defined at the IIS application root? – carlosfigueira May 15 '11 at 21:05
  • Yes, it is hosted in IIS. web.config is in the usual spot in application root dir. The service declaration's name is the class name. The contract is the correct interface name. The endpoint name is the same as the service name - is that a problem? – David May 15 '11 at 21:14
  • And once again Stack Overflow shows its value - you can look at a problem for a WEEK and then as soon as you post it some comment lets you figure it out. The issue was that a one-letter case difference between the name of the service in the configuration file and the actual name prevented WCF from creatingthe ServiceHost. The class had a name like MyServiceAssembly.MyService, and the service declaration said – David May 15 '11 at 22:30
  • @David - Post the result as an answer, and accept it. This makes it much easier for someone else to see the resolution. – Kirk Broadhurst May 16 '11 at 02:56
  • @David: I wrote you that you must correctly check that your config doesn't have any typo (lol, but I made typo myself in that word) - especially in `service/@name`. This is very common mistake and very big problem of WCF - it is called *simplified configuration* which creates default endpoints if WCF doesn't find corresponding configuration in config file but it only makes everything harder. – Ladislav Mrnka May 16 '11 at 08:44

2 Answers2

1

Have you tried setting up a host on the server to compliment the endpoint?

I think it would be something like this:

<service behaviorConfiguration="MyService.ServiceBehavior" name="MyService.ContentUploadService">    
<host>
   <baseAddresses>
      <add baseAddress="http://foo.com/ContentUploadService.svc"/>
   </baseAddresses>
</host>
<endpoint address="" binding="customBinding" indingConfiguration="binaryHttpBinding" contract="MyService.IContentUpload" name="MyService.ContentUploadService" />

Hope this is helpful

Brian Dishaw
  • 5,767
  • 34
  • 49
1

It looks to me like your service is using the default configuration, which would happen if it cannot find an explicit configuration. Make sure the name attribute of the element exactly matches the fully qualified name of your service class (namespace included).

David Nelson
  • 3,666
  • 1
  • 21
  • 24