1

我想将自定义消息头添加到 myService 并且我已经点击了链接:

http://trycatch.me/adding-custom-message-headers-to-a-wcf-service-using-inspectors-behaviors/

我已经很好地配置了它,并且在服务器端 IServiceBehavior.ApplyDispatchBehavior 正在通过调试运行,我可以在 ServiceDescription.Endpoints[0].Behaviors 中看到我的自定义行为,但是当我运行 ServiceEndpointCollection endpoints = MetadataResolver.Resolve(descriptions, address, MetadataExchangeClientMode.MetadataExchange,客户端);行为集合是空的,所以没有调用 IEndpointBehavior.ApplyDispatchBehavior 和 IEndpointBehavior.ApplyClientBehavior 函数 - 有人知道吗?这是我的配置文件:

<configuration>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="DefaultBehavior" name="MyService">
        <endpoint address="DatabaseService" behaviorConfiguration="MyCustomBehavior"
          binding="customBinding" bindingConfiguration="DefaultBindingConfig"
          contract="IMyService" />
        <endpoint address="mex" binding="netTcpBinding"
          bindingConfiguration="MexBindingConfig" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost/Services/SomeService" />
          </baseAddresses>
        </host>
      </service>      
    </services>    
    <bindings>
      <netTcpBinding>
        <binding name="MexBindingConfig" maxReceivedMessageSize="25000000" listenBacklog="30" maxConnections="30" portSharingEnabled="true">
          <readerQuotas maxArrayLength="25000000" maxStringContentLength="25000000" maxBytesPerRead="25000000" />
          <security mode="None">
          </security>
        </binding>
      </netTcpBinding>
      <customBinding>
        <binding name="DefaultBindingConfig" openTimeout="00:11:01" receiveTimeout="Infinite" sendTimeout="00:11:01" closeTimeout="00:11:01">
          <binaryMessageEncoding>
            <readerQuotas maxArrayLength="25000000" maxDepth="25000000" maxNameTableCharCount="25000000" maxStringContentLength="25000000" maxBytesPerRead="25000000" />
          </binaryMessageEncoding>
          <ImposedQuotas />
          <tcpTransport portSharingEnabled="true" maxBufferPoolSize="25000000" maxReceivedMessageSize="25000000" maxBufferSize="25000000">
          </tcpTransport>
        </binding>        
      </customBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="MyCustomBehavior">
          <MyCustomBehaviorExtension />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="DefaultBehavior">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceThrottling maxConcurrentCalls="1000" maxConcurrentSessions="1000" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <MyCustomBehaviorExtension />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add name="MyCustomBehaviorExtension" type="Namespace.MyCustomBehaviorExtension, MyDllName, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>      
    </extensions>
    <diagnostics performanceCounters="Off" />
  </system.serviceModel>
</configuration>
4

0 回答 0