I have a scenario where I need to use NetDataContractSerializer instead of DataContractSerializer.
So far I have used this method - http://www.pluralsight.com/community/blogs/aaron/archive/2006/04/21/22284.aspx - which looks pretty simple, but according to this http: // social.msdn.microsoft.com/forums/en-US/wcf/thread/cb0c56c0-3016-4cda-a3c7-8826f8cc5bb0/ , this approach is incorrect.
Looking around a bit more, I found the following: http://social.msdn.microsoft.com/forums/en-US/wcf/thread/f30ecd17-cac0-4cdc-8142-90b5f411936b/
Basically you need to run the following:
So this is what I have on the client side:
ChannelFactory<IPersonService> factory = new ChannelFactory<IPersonService>("WSHttpBinding_IPersonService"); foreach (OperationDescription desc in factory.Endpoint.Contract.Operations) { DataContractSerializerOperationBehavior dcsOperationBehavior = desc.Behaviors.Find<DataContractSerializerOperationBehavior>(); if (dcsOperationBehavior != null) { int idx = desc.Behaviors.IndexOf(dcsOperationBehavior); desc.Behaviors.Remove(dcsOperationBehavior); desc.Behaviors.Insert(idx, new NetDataContractSerializerOperationBehavior(desc));
And on the server side:
myServiceHost = new ServiceHost(typeof(PersonService), baseAddress); foreach (ServiceEndpoint endPoint in myServiceHost.Description.Endpoints) { foreach (OperationDescription desc in endPoint.Contract.Operations) { DataContractSerializerOperationBehavior dcsOperationBehavior = desc.Behaviors.Find<DataContractSerializerOperationBehavior>(); if (dcsOperationBehavior != null) { int idx = desc.Behaviors.IndexOf(dcsOperationBehavior); desc.Behaviors.Remove(dcsOperationBehavior); desc.Behaviors.Insert(idx, new NetDataContractSerializerOperationBehavior(desc));
The problem is that I am using VS client service proxies and standard VS.svc services. Therefore, I do not control the creation of a proxy server for a client or service, and the above code assumes this.
One of the comments in the post mentions that you can implement "IServiceBehavior, and the other - IClientBehavior", but I donβt know how to proceed to accept the above code and change it. Does anyone have any idea???
Cheers Anthony
vdh_ant
source share