客户端中不存在自定义EndpointBehavior

时间:2013-02-19 15:42:09

标签: wcf endpointbehavior

我想在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(description,address,MetadataExchangeClientMode.MetadataExchange,client); 行为集合是空的,所以 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>

0 个答案:

没有答案