gpt4 book ai didi

wcf - 使用 Protobuf-net 的端点行为配置 WCF

转载 作者:行者123 更新时间:2023-12-02 14:14:09 24 4
gpt4 key购买 nike

我有一个 WCF 服务 (.NET 4),它公开 4 个端点,其中一个端点配置有 protobuf-net (V1.0.0.280) 行为扩展。但是,我注意到 protobuf-net 行为会在所有定义的端点上启动,包括未配置 protbuf-net 的端点!我已将我的配置粘贴在下面。我错过了什么吗?非常感谢任何帮助..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 提供给我的端点内应用更改:

    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”

这提出了一种有趣的可能性,即契约定义(以及操作定义)本身在所有端点之间共享 - 但老实说我对此并不确定。如果是这种情况,我认为每个端点不可能有不同的处理器。然而,我不是 WCF 大师。这……令人费解。

关于wcf - 使用 Protobuf-net 的端点行为配置 WCF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7036209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com