1

如何将此 wcf 基本绑定转换为自定义绑定?

      <basicHttpBinding>
    <binding name="BasicHttpBinding_IAutenticacion" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Certificate" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>

提前谢谢!

4

1 回答 1

2

查看在线 wcf 绑定转换器http://webservices20.blogspot.co.il/2009/08/bindingbox-convert-wcf-bindings.html

编辑:当您使用此服务时,请记住在之前有一个标签(如默认示例中所示)。那么结果将是:

<!-- generated via Yaron Naveh's http://webservices20.blogspot.com/ -->

<customBinding>
  <binding name="NewBinding0">
    <security authenticationMode="CertificateOverTransport" messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" requireDerivedKeys="false" securityHeaderLayout="Lax" />
    <textMessageEncoding MessageVersion="Soap11" />
    <httpsTransport />
  </binding>
</customBinding>

<!-- generated via Yaron Naveh's http://webservices20.blogspot.com/ -->

编辑:这是您从代码创建此绑定的方式:

        var b = new CustomBinding();
        var s = SecurityBindingElement.CreateCertificateOverTransportBindingElement(
            MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
        s.SetKeyDerivation(false);
        s.SecurityHeaderLayout = SecurityHeaderLayout.Lax;

        b.Elements.Add(s);
        b.Elements.Add(new TextMessageEncodingBindingElement() {  MessageVersion = MessageVersion.Soap11});
        b.Elements.Add(new HttpsTransportBindingElement());

当你创建你的客户端时,你可以像这样设置证书:

c.ClientCredentials.ClientCertificate.Certificate
于 2012-07-01T21:38:32.767 回答