在 WCF 中使用自定义绑定并使用用户名客户端凭据保持消息安全模式?

问题描述 投票:0回答:3

我有可通过 Internet 访问的 WCF 服务,该服务使用

wsHttpBinding
以及消息安全模式和用户名客户端凭据。

<bindings>
    <wsHttpBinding>
        <binding name="wsHttpEndpointBinding" messageEncoding="Mtom" maxReceivedMessageSize="104857600">
           <readerQuotas maxArrayLength="104857600"/>
           <security mode="Message">
            <message clientCredentialType="UserName"/>
           </security>
        </binding>
    </wsHttpBinding>
</bindings>

我发现将数据从客户端传输到服务器需要太多时间。 我已了解到我可以使用

customBinding
binaryEncoding
模式来提供服务。

像这样:

<bindings>
   <customBindings>
     <binding name="NetHttpBinding">
       <binaryMessageEncoding />
       <httpTransport />
     </binding>
  </customBindings>
<bindings>

但是这里没有提及消息安全模式和客户端凭证类型。

如何将自定义绑定与

binaryEncoding
结合使用并使用用户名客户端凭据保持消息安全模式?

c# wcf wcf-security
3个回答
3
投票

我知道这不是您寻找的答案,但这是我的配置。 我使用带有

UserNameOverTransport
身份验证的自定义绑定。

它可能会为您提供有关需要更改哪些内容才能启动和运行的线索。

<customBinding>
    <binding name="MyCustomHttpBinding" receiveTimeout="00:20:00" sendTimeout="00:20:00">
        <security authenticationMode="UserNameOverTransport">
            <localServiceSettings maxClockSkew="Infinite" />
        </security>
        <mtomMessageEncoding maxBufferSize="2097152" messageVersion="Soap12" >
            <readerQuotas maxStringContentLength="2097152"/>
        </mtomMessageEncoding>
        <httpsTransport maxBufferSize="2097152" maxReceivedMessageSize="1073741824" transferMode="Streamed" />
    </binding>
</customBinding>

请记住,我使用 MTOM 编码,就我而言,它更适合我的场景。


1
投票

将 secureConversationBootstrap 设置为 UserNameForSslNegotiated。尝试类似于下面的绑定的操作。

<bindings>
<customBinding>
  <binding name="wss-username-binary">
    <transactionFlow/>

    <security 
authenticationMode="SecureConversation" 
messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">

      <secureConversationBootstrap 
authenticationMode="UserNameForSslNegotiated" 
messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
    </security>

      <binaryMessageEncoding />
    <httpTransport/>
  </binding>
</customBinding>
</bindings>

-1
投票

试试这个,它可能会对你有更多帮助——它有自定义绑定、自定义安全性和证书。

            <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange" />

        </service>

    </services>
    <bindings>
        <wsHttpBinding>

            <binding name="CommonBinding" maxReceivedMessageSize ="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                              maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                              maxNameTableCharCount="2147483647" />

                <security mode="Message">
                    <message clientCredentialType="UserName"  />
                </security>
            </binding>

        </wsHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="myServiceBehavior">

                <serviceCredentials>

                    <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Custom.Security.CustomUserNameValidator, Custom.Security" />
                    <clientCertificate>
                        <authentication certificateValidationMode= "PeerOrChainTrust"  />
                    </clientCertificate>
                    <serviceCertificate findValue="CertName" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
                </serviceCredentials>

                <serviceMetadata httpGetEnabled="True"/>
                <serviceAuthorization principalPermissionMode="Custom">
                    <authorizationPolicies>
                        <add policyType="Custom.Security.AuthorizationPolicy, Custom.Security" />
                    </authorizationPolicies>
                </serviceAuthorization>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>
© www.soinside.com 2019 - 2024. All rights reserved.