views:

77

answers:

1

I have a silverlight app that talks to a WCF service inside of an ASP.NET website. The following code works:

        var service = new ChannelFactory<IService>(new BasicHttpBinding()
                                                                    {
                                                                        MaxReceivedMessageSize = int.MaxValue
                                                                    }, 
                                                                    new EndpointAddress(Settings.ServiceUrl)).CreateChannel();

But I really want to take advantage of "binary encoding". To run the service with binary encoding, you cannot use the BasicHttpBinding, you need to use a CustomBinding! The following code is used in the same place, but yields an HTTP 415 Unsupported media type status from the web server. In a debugging session, no breakpoints are reached on the server.

            var service = new ChannelFactory<IService>(new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement()
                                                                                                                                 {
                                                                                                                                     MaxReceivedMessageSize = int.MaxValue
                                                                                                                                 }),
                                                                    new EndpointAddress(Settings.ServiceUrl)).CreateChannel(); 

I need help finding out why this setting doesnt work! BTW here is the service section in my web config on the server side:

  <system.serviceModel>
<bindings>
  <customBinding>
    <binding name="myBinding">
      <binaryMessageEncoding />
      <httpTransport authenticationScheme="Negotiate"/>
    </binding>
  </customBinding>
</bindings>
<services>
  <service name="myService">
    <endpoint address="" binding="customBinding"  bindingConfiguration="myBinding" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="wcfServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

A: 

I don't understand all Silverlight capabilities but at the moment I think your service doesn't work at all. Your custom binding does not have any transport binding element which is mandatory.

Try to change your binding:

<bindings> 
  <customBinding> 
    <binding name="myBinding"> 
      <binaryMessageEncoding /> 
      <httpTransport />
    </binding> 
  </customBinding> 
</bindings>
Ladislav Mrnka
Yes, thank you for pointing that out, I have edited the code above. I tried it again with the <HttpTransport /> element in the web.config as you described and there was absolutely no change in the issue, BasicHttpBinding works, and CustomBinding throws a NotFound Exception.
pete_w
Update- thanks for your help. I was able to adjust the local URL and add a dot "." to the address, which enables fiddler to monitor local traffic. Now I can see the real culprit is an HTTP 415 Unsupported Media Type from the debug web server.
pete_w
Debug web server? Do you mean Cassini (web server included in Visual studio)? I think Cassini does not support binary encoding. When developing advanced WCF services you should use IIS or self hosting.
Ladislav Mrnka