WCF Endpoint Behavior Configuration with Protobuf-net

I have a WCF service (.NET 4) that provides 4 endpoints, of which one endpoint is configured with the protobuf-net behavior extension (V1.0.0.280). However, I noticed that protobuf-net behavior works for ALL specific endpoints, including those that protbuf-net is not configured for! I pasted my config below. Am I missing something? Any help is appreciated. thanks

<service name="MyService" behaviorConfiguration="MyServiceBehavior"> <endpoint address="Http.Basic" binding="basicHttpBinding" bindingConfiguration="Http.Basic.Config" contract="IMyService" behaviorConfiguration="DefaultBehavior" /> <endpoint address="Http.Binary" binding="customBinding" bindingConfiguration="Http.Binary.Config" contract="IMyService" behaviorConfiguration="DefaultBehavior" /> <endpoint address="Tcp.Binary" binding="customBinding" bindingConfiguration="Tcp.Binary.Config" contract="IMyService" behaviorConfiguration="DefaultBehavior" /> <endpoint address="Http.ProtoBuf" binding="basicHttpBinding" bindingConfiguration="Http.Basic.Config" contract="IMyService" behaviorConfiguration="ProtoBufBehavior" /> <host> <baseAddresses> <add baseAddress="http://localhost:8085/MyService"/> <add baseAddress="net.tcp://localhost:8086/MyService"/> </baseAddresses> </host> </service> <behaviors> <serviceBehaviors> <behavior name="MyServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="DefaultBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> <behavior name="ProtoBufBehavior"> <ProtoBufSerialization /> </behavior> </endpointBehaviors> </behaviors> <bindings> <basicHttpBinding> <binding name="Http.Basic.Config" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> <customBinding> <binding name="Http.Binary.Config" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"> <binaryMessageEncoding /> <httpTransport allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" /> </binding> <binding name="Tcp.Binary.Config" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"> <binaryMessageEncoding /> <tcpTransport hostNameComparisonMode="StrongWildcard" /> </binding> </customBinding> </bindings> 
+7
source share
1 answer

This is strange, but (checks the code). I only ever apply changes to the endpoint provided to me by WCF:

  void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime) { ReplaceDataContractSerializerOperationBehavior(endpoint); } void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher) { ReplaceDataContractSerializerOperationBehavior(endpoint); } private static void ReplaceDataContractSerializerOperationBehavior(ServiceEndpoint serviceEndpoint) { foreach (OperationDescription operationDescription in serviceEndpoint.Contract.Operations) { ReplaceDataContractSerializerOperationBehavior(operationDescription); } } private static void ReplaceDataContractSerializerOperationBehavior(OperationDescription description) { DataContractSerializerOperationBehavior dcsOperationBehavior = description.Behaviors.Find<DataContractSerializerOperationBehavior>(); if (dcsOperationBehavior != null) { description.Behaviors.Remove(dcsOperationBehavior); description.Behaviors.Add(new ProtoOperationBehavior(description)); } } 

i.e. "given the endpoint (according to WCF), iterate over each operation (method) at that endpoint and change the serializer from DCS to PB"

This raises the intriguing possibility that the definitions of contracts (and therefore the definitions of operations) themselves are shared between all endpoints, but I'm honestly not sure about that. If so, I do not see that it is possible to have different processors per endpoint. However, I am not a WCF guru. This is ... puzzling.

+1
source

All Articles