C# 使用端点行为的WCF自定义序列化

C# 使用端点行为的WCF自定义序列化,c#,wcf,xml-serialization,C#,Wcf,Xml Serialization,我有一个在局域网上运行的服务,除了我创建的客户端之外,没有其他客户端。我一直在尝试删除默认的DataContractSerializerOperationBehavior,并将其替换为我编写的自定义行为,但迄今为止都没有成功。我正在使用C#4.5并在NettCPBinding上运行 我以protobuf net的实现为例编写了以下3个类。我只会把我认为是课堂上的主要部分包括在内。如果需要更多的细节,我会提供 CustomXmlObjectSerializer:XmlObjectSerialize

我有一个在局域网上运行的服务,除了我创建的客户端之外,没有其他客户端。我一直在尝试删除默认的DataContractSerializerOperationBehavior,并将其替换为我编写的自定义行为,但迄今为止都没有成功。我正在使用C#4.5并在NettCPBinding上运行

我以protobuf net的实现为例编写了以下3个类。我只会把我认为是课堂上的主要部分包括在内。如果需要更多的细节,我会提供

CustomXmlObjectSerializer:XmlObjectSerializer

CustomSerializerOperationBehavior:DataContractSerializerOperationBehavior

public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type> knownTypes) {
    return new CustomXmlObjectSerializer();
}

public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes) {
    return new CustomXmlObjectSerializer();
}
服务客户端的实例化如下所示:

serviceHost = new ServiceHost(typeof(ImplementationType));
var contract = typeof(ContractType);
var binding = GetBinding(configuration.Address, configuration.MaxTransferSize * 1024 * 1024);
var endpoint = serviceHost.AddServiceEndpoint(contract, binding, configuration.Address);
endpoint.Behaviors.Add(new CustomEndpointBehavior());
serviceHost.Open();
var binding = GetBinding(configuration.Address, configuration.MaxTransferSize * 1024 * 1024);
var endpoint = new EndpointAddress(configuration.Address);
factory = new ChannelFactory<ContractType>(binding, endpoint);
factory.Endpoint.Behaviors.Add(new CustomEndpointBehavior());
var binding=GetBinding(configuration.Address,configuration.MaxTransferSize*1024*1024);
var端点=新端点地址(configuration.Address);
工厂=新通道工厂(绑定,端点);
添加(新的CustomEndpointBehavior());
当我这样做时,我可以看到CustomEndpointBehavior将DataContractSerializeRopection行为替换为我的CustomSerializeRopection行为,但是我从来没有看到创建CustomXmlObjectSerializer的调用(以及它的后续使用)

我已经尝试将我的绑定从NetTcpBinding切换到BasicHttpBinding,但没有看到行为上的变化

是否有人知道为什么即使在观察到每个操作的默认DataContractSerializeRopection行为被替换为CustomSerializeRopection行为后,我实际上没有看到序列化行为的更改?

的可能重复项
var binding = GetBinding(configuration.Address, configuration.MaxTransferSize * 1024 * 1024);
var endpoint = new EndpointAddress(configuration.Address);
factory = new ChannelFactory<ContractType>(binding, endpoint);
factory.Endpoint.Behaviors.Add(new CustomEndpointBehavior());