我有一个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”

这引起了一个有趣的可能性,即契约(Contract)定义(以及操作定义)本身在所有端点之间共享-但老实说,我不确定。如果真是这样,我看不到每个端点都可能有不同的处理器。但是,我不是WCF专家。这令人困惑。

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

10-13 02:53