使用 Protobuf-net 的端点行为配置 WCF [英] Endpoint behavior configuration WCF with Protobuf-net
问题描述
我有一个 WCF 服务 (.NET 4),它公开 4 个端点,其中一个端点配置了 protobuf-net (V1.0.0.280) 行为扩展.但是,我注意到 protobuf-net 行为适用于 ALL 定义的端点,包括那些没有配置 protbuf-net 的端点!我在下面粘贴了我的配置.我错过了什么吗?非常感谢任何帮助.. thx
I have a WCF service (.NET 4) that exposes 4 endpoints of which one endpoint is configured with protobuf-net (V1.0.0.280) behavior extension. However, I noticed that protobuf-net behavior kicks in for ALL defined endpoints including the ones protbuf-net is not configured for! I have pasted my config below. Am I missing something? Any help is greatly appreciated .. thx
<service name="MyService" behaviorConfiguration="MyServiceBehavior">
<endpoint address="Http.Basic" binding="basicHttpBinding" bindingConfiguration="Http.Basic.Config" contract="IMyService" behaviorConfiguration="DefaultBehavior" />
<endpoint address="Http.Binary" binding="customBinding" bindingConfiguration="Http.Binary.Config" contract="IMyService" behaviorConfiguration="DefaultBehavior" />
<endpoint address="Tcp.Binary" binding="customBinding" bindingConfiguration="Tcp.Binary.Config" contract="IMyService" behaviorConfiguration="DefaultBehavior" />
<endpoint address="Http.ProtoBuf" binding="basicHttpBinding" bindingConfiguration="Http.Basic.Config" contract="IMyService" behaviorConfiguration="ProtoBufBehavior" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8085/MyService"/>
<add baseAddress="net.tcp://localhost:8086/MyService"/>
</baseAddresses>
</host>
</service>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="DefaultBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
<behavior name="ProtoBufBehavior">
<ProtoBufSerialization />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="Http.Basic.Config" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="Http.Binary.Config" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding />
<httpTransport allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" />
</binding>
<binding name="Tcp.Binary.Config" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding />
<tcpTransport hostNameComparisonMode="StrongWildcard" />
</binding>
</customBinding>
</bindings>
推荐答案
这很奇怪,但是(检查代码)我只在 WCF 提供给我的端点内应用更改:>
That is odd, but (checks the code) I only ever apply changes within an endpoint supplied to me by WCF:
void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
ReplaceDataContractSerializerOperationBehavior(endpoint);
}
void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{
ReplaceDataContractSerializerOperationBehavior(endpoint);
}
private static void ReplaceDataContractSerializerOperationBehavior(ServiceEndpoint serviceEndpoint)
{
foreach (OperationDescription operationDescription in serviceEndpoint.Contract.Operations)
{
ReplaceDataContractSerializerOperationBehavior(operationDescription);
}
}
private static void ReplaceDataContractSerializerOperationBehavior(OperationDescription description)
{
DataContractSerializerOperationBehavior dcsOperationBehavior = description.Behaviors.Find<DataContractSerializerOperationBehavior>();
if (dcsOperationBehavior != null)
{
description.Behaviors.Remove(dcsOperationBehavior);
description.Behaviors.Add(new ProtoOperationBehavior(description));
}
}
即给定一个端点(通过 WCF),循环遍历该端点中的每个操作(方法),并将序列化程序从 DCS 更改为 PB"
i.e. "given an endpoint (by WCF), loop over each operation (method) in that endpoint, and change the serializer from DCS to PB"
这提出了一个有趣的可能性,即合同定义(以及操作定义)本身在所有端点之间共享 - 但老实说,我不确定这一点.如果是,我认为每个端点不可能有不同的处理器.但是,我不是 WCF 专家.这……令人费解.
This raises the intriguing possibility that the contract definitions (and hence the operation definitions) are themselves shared between all the endpoints - but I am honestly not sure about that. If that is the case, I don't see that it would ever be possible to have different processors per endpoint. I am not, however, a WCF-guru. This is... perplexing.
这篇关于使用 Protobuf-net 的端点行为配置 WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!