Database Reference
In-Depth Information
3.
We need the DataContractSerializer to use a ProxyDataContractResolver class to
transform the client proxy to the client entity for the WCF service's client. For this, we'll
create an operation behavior attribute and apply the attribute on the GetClient() service
method. Add the code in Listing 9-34 to create the new attribute. Keep in mind that the
ProxyDataContractResolver class resides in the Entity Framework namespace.
Listing 9-34. Our Custom Operation Behavior Attribute
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.Data.Objects;
namespace Recipe8
{
public class ApplyProxyDataContractResolverAttribute : Attribute,
IOperationBehavior
{
public void AddBindingParameters(OperationDescription description,
BindingParameterCollection parameters)
{
}
public void ApplyClientBehavior(OperationDescription description,
ClientOperation proxy)
{
DataContractSerializerOperationBehavior
dataContractSerializerOperationBehavior =
description.Behaviors
.Find<DataContractSerializerOperationBehavior>();
dataContractSerializerOperationBehavior.DataContractResolver =
new ProxyDataContractResolver();
}
public void ApplyDispatchBehavior(OperationDescription description,
DispatchOperation dispatch)
{
DataContractSerializerOperationBehavior
dataContractSerializerOperationBehavior =
description.Behaviors
.Find<DataContractSerializerOperationBehavior>();
dataContractSerializerOperationBehavior.DataContractResolver =
new ProxyDataContractResolver();
}
public void Validate(OperationDescription description)
{
}
}
}
 
Search WWH ::




Custom Search