how to know if a WCF service uses protobuf-net?

1.4k views Asked by At

Im trying to get google protocol buffer serialization to work with a WCF service. The service and client do start both and objects are returned to the client but I'm not sure what serialization is used now. Changing the names in "behaviorExtensions" to something non-existing makes no difference, and the service has no protobuf configuration at all, thats why I'm doubting.

Here's the relevant configuration on the client side:

<system.serviceModel>
  <behaviors>
<endpointBehaviors>
        <behavior name="protoEndpointBehavior">
          <!--<protobuf/>-->
         </behavior>
</endpointBehaviors>
   </behaviors>

<bindings>
    <netTcpBinding>
      <binding name="netTcpIoService">
     <reliableSession inactivityTimeout="infinite" enabled="true" />
    </binding>
    </netTcpBinding>
</bindings>
<client>
    <endpoint address="net.tcp://localhost:9001/IoService/IoService"                     binding="netTcpBinding" bindingConfiguration="netTcpIoService"
                contract="IoService.IIoService" name="netTcpIoService" behaviorConfiguration="protoEndpointBehavior">
            <identity>
            <userPrincipalName value="[email protected]" />
            </identity>
    </endpoint>

</client>
<extensions>
      <behaviorExtensions>
        <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.480, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/>
      </behaviorExtensions>
</extensions>
</system.serviceModel> 

and the configuration on the service:

<system.serviceModel>
    <behaviors>
    <endpointBehaviors>
        <behavior name="protoEndpointBehavior">
          <!--<protobuf/>-->
        </behavior>
    </endpointBehaviors>
    </behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
        <netTcpBinding>
          <binding name="netTcpIoService">
             <reliableSession inactivityTimeout="infinite" enabled="true" />
            </binding>
        </netTcpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="serviceBehaviour" name="ioService.IoService">
            <endpoint address="IoService" binding="netTcpBinding" bindingConfiguration="netTcpIoService" name="netTcpIoService" contract="ioService.IIoService" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.tcp://localhost:9001/IoService" />
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

The service interface and the object to be serialized:

[ServiceContract(CallbackContract = typeof(IIoServiceCallback)), ProtoBuf.ProtoContract]
public interface IIoService {
    [OperationContract]
    Article GetArticle(string number);
}

    [Serializable]
    [ProtoContract]
    public class Article : EntityBase
    {
        [ProtoMember(1)]
        public string Id;

        [ProtoMember(2)]
        public string Number;

        [ProtoMember(3)]
        public string Description;

        [ProtoMember(4)]
        public string Name;
}

Edit:

After realizing that behaviours are not shared at the client and server and that they must have the behaviour configured at both points I added this to the service config:

<extensions>
      <behaviorExtensions>
        <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.480, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/>
      </behaviorExtensions>
</extensions>

Then the service would not work because it could not the assembly with version 2.0.0.480 and it had to be changed to .668. then it worked again. But I'm not seeing improved performane over the version without the extension behaviour so I'm still in doubt.

I did add

ProtoBuf.Serializer.PrepareSerializer<Article>(); 

to the service but it did not help.

Still not sure what to do to check if the Article objects are serialized through the protobuf-net.dll software.

1

There are 1 answers

0
Serve Laurijssen On BEST ANSWER

Finally figured it all out by letting the service use .NET serialization and the client protobuf. then null would be returned. Then made the service use protobuf serialization too and valid objects were returned.

These are the correct config settings, the same structure for both client and service:

 <system.serviceModel>     
    <behaviors>
        <endpointBehaviors>
            <behavior name="protobuf">
                <protobuf />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <client_or_services/service>
        <endpoint address="net.tcp://localhost:9001/Service/Service" 
            binding="netTcpBinding" bindingConfiguration="netTcpService" behaviorConfiguration="protobuf"
            contract="IoService.IIoService" name="netTcpService">
        </endpoint>
    </client_or_services/service>
    <extensions>
          <behaviorExtensions>
            <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.668, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/>
          </behaviorExtensions>
    </extensions>   
  </system.serviceModel>