wcf - 使用用户名通过 https 配置 WCF 以获得 WS-Security

标签 wcf ws-security

我正在尝试使用 WCF 客户端通过 https 调用基于 Java、启用 WS-Security 的 Web 服务,但似乎无法获得正确的安全配置。使用 SvcTraceViewer,我在尝试过的任何安全配置中都没有看到预期的安全 header 。

我最近的安全配置是:

    <wsHttpBinding>
        <binding name="MySoapBinding" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8"
            useDefaultWebProxy="true">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="TransportWithMessageCredential">
            <transport/>
            <message clientCredentialType="UserName" negotiateServiceCredential="false" establishSecurityContext="false"/>
          </security>
        </binding>
    </wsHttpBinding>

我在代码中设置了用户名/密码,如下所示:

    svc.ClientCredentials.UserName.UserName = TestBase.userName;
    svc.ClientCredentials.UserName.Password = TestBase.password;

Java Web 服务需要如下所示的安全 header :

<wsse:Security soap:mustUnderstand="1">
<wsu:Timestamp wsu:Id="Timestamp-bf41c571-7d32-438c-937e-7d83a3ac2d14">
<wsu:Created>2010-12-27T16:43:16Z</wsu:Created>
<wsu:Expires>2010-12-27T16:48:16Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-4c9b30b1-d697-4c64-89cb-a6d7e857aebf">
<wsse:Username>MyUserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MyPassword</wsse:Password>
<wsse:Nonce>pzLdD4S+OCDG6Ut9Ur1oOQ==</wsse:Nonce>
<wsu:Created>2010-12-27T16:43:16Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>

我根本看不到安全 header 。

我在网上阅读了大量有关传输与消息级安全性和安全模式的内容,但似乎找不到正确的选项集。我应该如何配置我的绑定(bind)

  • https 通信
  • SOAP header 中的用户名/密码,采用纯文本格式 (WS-Security)
  • 需要时间戳
  • 需要随机数

最佳答案

事实证明,Rick Strahl 也遇到了几乎完全相同的问题。事实证明,SvcTraceViewer 确实没有显示实际的在线消息。不过,他的博客概述了通过 Charles(或者在我的例子中是免费的 Fiddler 2)代理查看实际消息的过程。

事实证明,我正在根据我正在调用的 Web 服务的要求发送时间戳元素,但如果我这样做,WCF 会要求在响应中包含时间戳(我没有收到)。该错误消息非常具有误导性。幸运的是,我可以更改服务以返回时间戳。

http://www.west-wind.com/weblog/posts/205198.aspx

关于wcf - 使用用户名通过 https 配置 WCF 以获得 WS-Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4543915/

相关文章:

本地运行时出现 WCF Azure 403 错误

wcf - ClaimsPrincipal 在到达 WCF 服务时为 null

java - 使用 ws-security 签署消息时要签署什么

c# - WCF、声明、ADFS 3.0

excel - PowerPivot 未将基本身份验证中的授权 header 发送到 OData Svc

wcf - IIS 托管的 WCF 休息服务出现 400 错误,URL 是否太长?

java - SOAP 故障异常 : WSS1601: Security Requirements not met

java - 使用 JAXB 防止 XXE 攻击

WCF 客户端 - 如何处理或忽略 MustUnderstand header 元素?

c# - 使用 WS-Security web 服务的 WCF 客户端