使用 WSE 3.0 添加 SOAP:HEADER 用户名和密码
我已经成功创建了一个 WS 客户端,该客户端在不使用身份验证时可以正常工作。
然而,服务器(WebSphere)现在需要添加 ws-security 用户名令牌,而我很难做到这一点。生成的 SOAP 消息应该如下所示:
<soapenv:Envelope
xmlns:ns="http://foo.bar/1.0"
xmlns:ns1="http://www.witsml.org/schemas/140"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>foo</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">bar</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">foooooobar==</wsse:Nonce>
<wsu:Created>2010-01-25T13:09:24.860Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ns:fooBar>...</ns:fooBar>
</soapenv:Body>
我已经下载并安装了 Microsoft 的 WSE 3.0 SDK,并在我的 Visual Studio 2005 项目中添加了对该 DLL 的引用。
我现在可以访问 Microsoft.Web.Services3.* 命名空间,但目前我不知道如何继续。
客户端代码是由 Web 引用自动生成的,因此我只需执行少量工作即可将消息发送到服务器未经身份验证:
WS.FooResultHttpService ws = new WS.FooResultHttpService();
ws.Url = "http://foo.bar.baz";
ws.SendSomething(message);
我刚刚开始使用 Microsoft 进行调查。 Web.Services3.Security.Tokens.UsernameTokenManager
,但到目前为止我还无法启动并运行任何东西。
任何提示将不胜感激,因为我似乎无法在网上找到任何好的食谱。
谢谢!
I have successfully created a WS client that works correctly when NOT using authentication.
However, the server (WebSphere) now requires adding a ws-security username token, and I'm having a hard time doing this. The resulting SOAP message is supposed to look something like this:
<soapenv:Envelope
xmlns:ns="http://foo.bar/1.0"
xmlns:ns1="http://www.witsml.org/schemas/140"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>foo</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">bar</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">foooooobar==</wsse:Nonce>
<wsu:Created>2010-01-25T13:09:24.860Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ns:fooBar>...</ns:fooBar>
</soapenv:Body>
I've downloaded and installed Microsoft's WSE 3.0 SDK and added a reference to the DLL in my Visual Studio 2005 project.
I now have access to the Microsoft.Web.Services3.* namespaces, but I'm currently stumped on how to proceed.
The client code has been generated automatically by a web reference, so I only do a minor amount of work to send the message to the server unauthenticated:
WS.FooResultHttpService ws = new WS.FooResultHttpService();
ws.Url = "http://foo.bar.baz";
ws.SendSomething(message);
I've just begun to investigate using Microsoft.Web.Services3.Security.Tokens.UsernameTokenManager
, but so far I haven't been able to get anything up and running.
Any hints would be greatly appreciated, as I can't seem to find any good recipes on the net.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您的代理类继承自
Microsoft.Web.Services3.WebServicesClientProtocol
。您可以通过更改代理类本身来完成此操作,也可以使用 wsewsdl3.exe 与
/type:webClient
开关。然后,您可以像这样传递凭据:
这就是我过去为让 WSE3.0 在 Studio 2008 中运行而所做的事情。希望有所帮助。
Make sure your proxy class inherits from
Microsoft.Web.Services3.WebServicesClientProtocol
.You can do this either by changing the proxy class itself, or by generating it via the command line using wsewsdl3.exe with the
/type:webClient
switch.You can then pass the credentials like this:
This is what I've done in the past to get WSE3.0 going in Studio 2008. Hope that helps.
不幸的是,在阅读 wsanville 的出色答案之前,它已经工作了。
为了帮助其他人,我发布了使其与 Visual Studio 2005 一起使用所需的所有步骤:
YourWsNameHttpServiceWse
。 相同SetClientCredential
。我最终用代码完成了几乎所有事情,而不是依赖于使用 C# DLL 构建的配置文件。代码最终如下所示:
我创建了自己的策略,如下所示:
最后,WebSphere 服务器响应 表示消息寻址属性的必需标头不存在,并检查传出消息(使用很好的工具 Fiddler)我看到来自服务器的 SOAP 错误表明 Action 标头是丢失的。
我尝试自己设置
wsa:Action
元素,但没有成功:问题是,即使我设置了一个操作,当它通过网络发送时,它也是空的。结果我必须打开 WSE 代理类并在那里编辑一个属性:
之后,一切都很顺利。
Got it working, unfortunately before reading wsanville's great answer.
To help others, I'm posting all the steps I needed to do to get it working with Visual Studio 2005:
YourWsNameHttpServiceWse
. This is essentially the same as running wsewsdl3.exeSetClientCredential
.I ended up doing almost everything in code, instead of relying on the config-files that are built with my C# DLL. The code ended up looking like this:
I created my own policy, which looked like this:
Finally, the WebSphere server responded that A required header representing a Message Addressing Property is not present, and inspecting the outgoing message (using the nice tool Fiddler) I saw the SOAP fault from the server indicated that the Action header was missing.
I tried in vain to set the
wsa:Action
element myself:The problem was that even if I set an action, when it was sent over the wire, it was empty. Turned out I had to open the WSE proxy class and edit an attribute there:
After that, it all worked out nicely.