I have a scenario where I need to use the NetDataContractSerializer instead of the DataContractSerializer.
Up until now I have been using this method - http://www.pluralsight.com/community/blogs/aaron/archive/2006/04/21/22284.aspx - which appears quite simple but according to this http://social.msdn.microsoft.com/forums/en-US/wcf/thread/cb0c56c0-3016-4cda-a3c7-8826f8cc5bb0/ the 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 the VS generated client service proxies and the standard VS .svc services. So I'm not controlling the creation of the client proxy or the service and the above code assumes that.
One of the comments in the post mentions that you would be able to implement "IServiceBehavior and another one is IClientBehavior" but I have no idea how to go about taking the above code and changing it. Does anyone have any ideas???
Cheers Anthony
NetDataContractSerializer
? – Kallick