【问题标题】:Convert wsHttpBinding to customBinding将 wsHttpBinding 转换为 customBinding
【发布时间】:2010-11-18 16:53:30
【问题描述】:

如何将以下 wsHttpBinding 转换为 customBinding?我需要这样做,这样我才能增加时钟偏差。这是用于 http。

 <wsHttpBinding>
    <binding name="wsHttpSecurityOptions" maxReceivedMessageSize="10485760" maxBufferPoolSize="524288">
      <security mode="Message">
        <message clientCredentialType="UserName" establishSecurityContext="true" negotiateServiceCredential="true"/>
        <transport clientCredentialType="Certificate" proxyCredentialType="None"/>
      </security>
      <readerQuotas maxStringContentLength="500000"/>
    </binding>
  </wsHttpBinding>

我的尝试(如下)失败并显示错误消息“找不到与具有绑定 CustomBinding 的端点的方案 https 匹配的基地址”,但我看不到如何配置 UserName 消息模式安全性。

  <customBinding>
    <binding name="wsHttpSecurityOptions">
      <transactionFlow />
      <security authenticationMode="UserNameForSslNegotiated">
        <secureConversationBootstrap authenticationMode="UserNameForSslNegotiated">
          <localServiceSettings maxClockSkew="00:10:00" />
        </secureConversationBootstrap>
        <localServiceSettings maxClockSkew="00:10:00" />
      </security>
      <textMessageEncoding>
        <readerQuotas maxStringContentLength="500000"/>
      </textMessageEncoding>
      <httpsTransport maxReceivedMessageSize="10485760" maxBufferPoolSize="524288" />
    </binding>
  </customBinding>

【问题讨论】:

    标签: wcf wcf-binding


    【解决方案1】:

    经过更多搜索后,我找到了 Yaron Naveh 的 cool tool,它进行了转换,产生了以下结果(我在时钟偏差中添加了)

      <customBinding>
        <binding name="wsHttpSecurityOptions">
          <transactionFlow />
          <security authenticationMode="SecureConversation" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
            <secureConversationBootstrap authenticationMode="UserNameForSslNegotiated" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
              <localServiceSettings maxClockSkew="00:10:00" />
            </secureConversationBootstrap>
            <localServiceSettings maxClockSkew="00:10:00" />
          </security>
          <textMessageEncoding />
          <httpTransport maxBufferSize="10485760" maxReceivedMessageSize="10485760" />
        </binding>
      </customBinding>
    

    再次感谢 Yaron,我希望我能在问另一个问题之前找到它

    【讨论】:

    • +1 链接到非常酷的工具(WCF BindingBox),希望它在不久的将来也能支持与 WS-Federation 相关的绑定。
    • 我在使用这个 customBinding 时遇到了以下错误:不支持寻址版本“AddressingNone (schemas.microsoft.com/ws/2005/05/addressing/none)”。
    • 我正在使用两个绑定,是否需要为它们分别生成。
    • 链接已失效 :( 没有任何替代迹象或该工具的源代码。很遗憾,因为它听起来像是一个很棒的工具。
    【解决方案2】:

    检查此解决方案。它通过代码创建自定义绑定,修改其时钟偏差,并将其设置为要使用的绑定。 (来源:http://sandrinodimattia.net/blog/posts/wcf-and-fixing-clienthost-time-issues-maxclockskew-quickly/

    ServiceHost service = new ServiceHost(typeof(Calculator));
    Binding currentBinding = service.Description.Endpoints[0].Binding;
    
    // Set the maximum difference in minutes
    int maxDifference = 300;
    // Create a custom binding based on an existing binding
    CustomBinding myCustomBinding = new CustomBinding(currentBinding);
    // Set the maxClockSkew
    var security = myCustomBinding.Elements.Find<SymmetricSecurityBindingElement>();
    security.LocalClientSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
    security.LocalServiceSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
    // Set the maxClockSkew
    var secureTokenParams = (SecureConversationSecurityTokenParameters)security.ProtectionTokenParameters;
    var bootstrap = secureTokenParams.BootstrapSecurityBindingElement;
    bootstrap.LocalClientSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
    bootstrap.LocalServiceSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
    
    // Update the binding of the endpoint
    service.Description.Endpoints[0].Binding = myCustomBinding;
    

    【讨论】:

      猜你喜欢
      • 2010-10-06
      • 2014-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多