NetDataContractSerializer and WCF

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)); //return true; } } IPersonService svc = factory.CreateChannel(); 

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)); //return true; } } } myServiceHost.Open(); 

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

+6
c # wcf
source share

No one has answered this question yet.

See related questions:

394
REST / SOAP endpoints for WCF service
392
WCF vs ASP.NET Web API
382
WCF - How to increase message size
377
What is the best way to work around a WCF problem using `` WCF?
5
Using IErrorHandler and TCP Message Security timeout
3
IsReference DataContract Property with WCF and DataContractSerializer
one
Switching to a WCF Service Using NetDataContractSerializer
one
WCF - NullReferenceException on the most basic WCF call
one
How to set the appropriate WCF service names both in the Web.Config file and in s.svc ServiceHost
0
wcf netdatacontractserializer exception Serialization idictionary with enumeration as key

All Articles