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

发布于 2024-10-09 01:46:51 字数 2350 浏览 6 评论 0原文

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

我最近的安全配置是:

    <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 服务需要这样的安全标头:

<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>

我根本看不到安全标头。

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

  • https 通信
  • 的绑定SOAP 标头中的用户名/密码,以纯文本形式 (WS-Security)
  • 需要时间戳
  • 需要 Nonce

I'm trying to call a Java based, WS-Security enabled web service over https using a WCF client and can't seem to get the security configuration right. Using SvcTraceViewer, I don't see the expected security header with any of the security configurations I have tried.

My most recent security configuration is:

    <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>

and I set the username/password in code like this:

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

The Java web service expects a security header like this:

<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>

I see no Security header at all.

I have read quite a bit online about transport vs. message level security and security modes, but can't seem to find the right set of options. How should I configure my binding for

  • https communication
  • Username/passowrd in the SOAP header, in plain text (WS-Security)
  • Timestamp required
  • Nonce required

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浊酒尽余欢 2024-10-16 01:46:51

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

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

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

Turns out Rick Strahl had almost exactly the same issue. It turns out that SvcTraceViewer does not show the actual on-the-wire message. However, his blog outlines a procedure to proxy through Charles (or in my case Fiddler 2, which is free) to see the actual message.

It turns out that I'm sending a Timestamp element as required by the web service I'm calling, but if I do, WCF demands a Timestamp in the response (which I'm not getting). The error message is quite misleading. Fortunately I can have the service changed to return a Timestamp.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文