How can I test if the DataContractSerializer was effectively replaced by XmlProtoSerializer?

StackOverflow https://stackoverflow.com/questions/22696054

  •  22-06-2023
  •  | 
  •  

Question

I have a series of self-hosted WCF services (using netTcpBinding) that I want to enhance by using the fantastic protobuf-net serializer.

I configured both the client and the service endpoints with the custom behavior extensions as instructed in the documentation of the ProtoEndpointBehavior class (see here). My tests ran fine from the very first try, however, I'm very skeptical of WCF-stuff running fine at the very first try ;)

Is there a simple way in which I can assert that the default DataContractSerializer was replaced by the XmlProtoSerializer?

I would really favor a test that can be also coded as part of a unit test. I wouldn't like the protobuf-net library to be inadvertently disabled by careless tampering of the .config file.

Was it helpful?

Solution

If you call your service in wcf test client, you will see < proto/> tag in the body of response proto call

If you configure your client to use proto behaviour and call service with "inadvertently disabled protobuf", your answer will be null because of different serializers. You can check it in your test

var address = new EndpointAddress( url );
var binding = GetBinding( address.Uri );
var factory = new ChannelFactory<TService>( binding, address );
factory.Endpoint.EndpointBehaviors.Add( CreateProtobufEndpointBehavior() );
var client = factory.CreateChannel();
var answer = client.GetSomeInt();

AssertAnswerIsNotNull(answer);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top