0
votes

I have a WCF service with a customBinding endpoint.

<customBinding>
    <binding name="customBinding" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">
      <binaryMessageEncoding>
        <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
      </binaryMessageEncoding>
      <httpTransport maxReceivedMessageSize="40194304" />
    </binding>
  </customBinding>     

My service is :

<services>
  <service  name="Test2">
     <endpoint address="" binding="customBinding" bindingConfiguration="customBinding" contract="MyServiceContract.ContractInterface">
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

However, in my client application, whenever I add a Service Reference, the resulting reference is a BasicHTTPBinding (in app.config)

What can I do to "force" the client to use custombinding?

Thanks Alex

2

2 Answers

1
votes

The service is not using the binding you specified. My guess is that the service name is actually "MyServiceContract.Test2" (or something similar) instead of just "Test2", so when WCF didn't find any matching <service> element to the service class, it simply used the default endpoint, which happens to use basicHttpBinding.

1
votes

Have you defined a class for your custom binding (a class derived from System.ServiceModel.Channels.Binding)?

If so, have you added the new binding into the config binding extensions?

<extensions>
  <bindingExtensions>
    <add name="myCustomeBinding" type="MyCustomeBinding, MyCustomeBindingLibrary" />
  </bindingExtensions>
</extensions>

The job of the binding is to define the "recipe" for creating the WCF channel. Basically the recipe consists of a list of binding elements.

Which bindings elements you select in your recipe decides the nature of the communication that the WCF channel will implement.

At the absolute minimum your recipe of binding elements needs to include:

  • Message encoding (text/binary etc)
  • Transport (HTTP/TCP etc)

If you don't have a class defining your binding then WCF has no option but to create a channel based on the default values for these two binding elements, and so has probably been designed to switch to basicHttpBinding when no binding has is defined.

That would be my guess.