简体   繁体   English

WCF:在代码中将CustomBinding设置为“仅传输安全性”

[英]WCF: set CustomBinding to Transport Only Security in code

We use a customBinding in our project, and I want to set it Transport Only Security in the code, which should be equivalent to XML as bellow : 我们在我们的项目中使用了customBinding,我想在代码中将其设置为“仅传输安全性”,它应该与XML等效,如下所示:

<security mode="Transport" />

I searched a lot but I don't find how to do it, because my CustomBinding class extends System.ServiceModel.Channels.Binding so there is no field security. 我进行了很多搜索,但找不到具体方法,因为我的CustomBinding类扩展了System.ServiceModel.Channels.Binding因此没有字段安全性。

Also I'm looking for the equivalent in code to the below xml: 我也在寻找与以下xml等效的代码:

<message algorithmSuite="Basic128/Basic192/Basic256/Basic128Rsa15/Basic256Rsa15/TripleDes/TripleDesRsa15/Basic128Sha256/Basic192Sha256/TripleDesSha256/Basic128Sha256Rsa15/Basic192Sha256Rsa15/Basic256Sha256Rsa15/TripleDesSha256Rsa15"
         clientCredentialType="Certificate/IssuedToken/None/UserName/Windows"
         establishSecurityContext="Boolean"
         negotiateServiceCredential="Boolean" />

You need to use httpsTransport for example 您需要使用例如httpsTransport

<httpsTransport authenticationScheme="Basic"  manualAddressing="true" maxReceivedMessageSize="524288000" transferMode="Streamed" />

More info check 更多信息检查

For Transport security mode in Custom binding, we usually use HttpsTransport section to configure. 对于自定义绑定中的传输安全模式,我们通常使用HttpsTransport部分进行配置。
For message security, it is implemented by the security section. 对于消息安全性,它由安全性部分实现。
Please refer to the below configuration. 请参考以下配置。

<customBinding>
        <binding name="wss-username-binary">
          <transactionFlow/>
          <security
      authenticationMode="SecureConversation"
      messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
            <secureConversationBootstrap
      authenticationMode="UserNameForSslNegotiated"
      messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
          </security>
          <binaryMessageEncoding />
          <httpsTransport/>
        </binding>
      </customBinding>

For the authentication mode in WCF, please refer to the below document. 有关WCF中的身份验证模式,请参考以下文档。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/securitybindingelement-authentication-modes https://docs.microsoft.com/zh-cn/dotnet/framework/wcf/feature-details/securitybindingelement-authentication-modes
Feel free to let me know if there is anything I can help with. 请随时告诉我是否有什么我可以帮助的。

Updated. 更新。

 //Under the WCF service created by the below binding, server provides a certificate to ensure the message security, and the client provides a username/password to represent an identity
        var b = SecurityBindingElement.CreateUserNameForCertificateBindingElement();
        TextMessageEncodingBindingElement encoding = new TextMessageEncodingBindingElement();
        HttpsTransportBindingElement transport = new HttpsTransportBindingElement();
        CustomBinding binding = new CustomBinding(b, encoding, transport);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM