繁体   English   中英

WSHttpBinding 绑定,客户端认证

[英]WSHttpBinding binding, client authentication

我是 wcf 的新手并使用 wshttpbinding,但我想从服务客户端(我必须通过)中删除用户名和密码,我的客户端代码是

RServiceClient serviceClient = new RServiceClient();
serviceClient.ClientCredentials.Windows.ClientCredential.UserName = "UserName";
serviceClient.ClientCredentials.Windows.ClientCredential.Password = "Password";

我不想传递这个用户名和密码。

我的客户端 app.config 是:

     <binding name="WSHttpBinding_IRService" 
              closeTimeout="00:01:00"
              openTimeout="00:01:00" 
              receiveTimeout="00:10:00" 
              sendTimeout="00:01:00"
              bypassProxyOnLocal="false" 
              transactionFlow="false"    
              hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="524288" 
              maxReceivedMessageSize="65536"
              messageEncoding="Text" 
              textEncoding="utf-8" 
              useDefaultWebProxy="true"
              allowCookies="false">
              <readerQuotas maxDepth="32" 
                            maxStringContentLength="8192" 
                            maxArrayLength="16384"
                            maxBytesPerRead="4096" 
                            maxNameTableCharCount="16384" />
              <reliableSession ordered="true" 
                               inactivityTimeout="00:10:00"
                               enabled="false" />
              <security mode="Message">
               <transport clientCredentialType="Windows" 
                          proxyCredentialType="None"
                          realm="" />
               <message clientCredentialType="Windows"                    
                        negotiateServiceCredential="true"
                        algorithmSuite="Default" />
              </security>
            </binding>

rite now 服务托管在 web 中。 service.config 或客户端 app.config 是否有任何更改。 谷歌搜索后我的薄弱知识是改变应该是客户端,但我无法做到这一点。 :-(

注意:我的合同也需要会话。 提前谢谢。

您需要在服务器端更改 web.config,您的客户端 web.config 将在 web 参考刷新后自动更新。 如果您不想使用登录名/密码,我可以建议您设置相互证书身份验证。

这种方法安全且可与其他 WS 堆栈互操作(例如 Java CXF,...)

对于相互认证身份验证:您将需要一个 X.509 证书以允许客户端确保服务器确实是假装的,并在客户端需要另一个 X.509 证书。

这里是 web.config 的示例, MSDN上的更多信息:

   <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceCredentialBehavior">
          <serviceCredentials>
            <serviceCertificate findValue="Contoso.com" 
                                storeLocation="LocalMachine"
                                storeName="My" 
                                x509FindType="FindBySubjectName" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="serviceCredentialBehavior" 
               name="ServiceModel.Calculator">
        <endpoint address="http://localhost/Calculator" 
                  binding="wsHttpBinding"
                  bindingConfiguration="InteropCertificateBinding"
                  name="WSHttpBinding_ICalculator"
                  contract="ServiceModel.ICalculator" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="InteropCertificateBinding">
          <security mode="Message">
            <message clientCredentialType="Certificate"
                     negotiateServiceCredential="false"
                     establishSecurityContext="false" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client />
  </system.serviceModel>
</configuration>

暂无
暂无

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

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