如何将安全标头添加到SOAP消息?
我正在尝试使用我们的提供商从C#应用中使用Java编写的Web服务。是时候进行通信了,我得到了:
I'm trying to consume a WebService written in Java by our provider from our C# App. When it's time to communicate, I get this:
WSDoAllReceiver:传入的消息不包含必需的安全标头
WSDoAllReceiver: Incoming message does not contain required Security header
从昨天开始,我试图找出如何向SOAP消息中添加安全标头。
Since yesterday I'm trying to find out how to add security header to a SOAP message.
是,我阅读了此内容(对如何创建SOAP毫无头绪< wsse:Security> ; header ),但它不起作用。
Yes, I read this ( Clueless about how to create SOAP <wsse:Security> header ) but it did not work.
我环顾四周,这似乎是一个相当疑问的问题。我想知道是否可以在这里获得一些帮助,一些指针,一些代码来使我入门。
I looked around and this seems to be a rather asked question. I wonder if I can get some help here, some pointers, some code, to get me started.
我实际上设法通过使用WSE来实现。有趣的是,提供商的Web服务不能与WSE 3.0一起使用,但是可以与WSE 2.0一起使用。以下是步骤
I actually managed to achieve that by using WSE. The funny thing is that the provider's Web Services would not work with WSE 3.0, but they did with WSE 2.0. Here are the steps
- 获取 WSE 2.0
- 将Web参考添加到项目中
- 在Web参考代理实现中:
替换
public partial class UserWS : System.Web.Services.Protocols.SoapHttpClientProtocol
by
public partial class UserWS : Microsoft.Web.Services2.WebServicesClientProtocol
- 调用Web服务之前:
设置身份验证信息
UsernameToken token = new UsernameToken("user", "pwd", PasswordOption.SendPlainText);
yourProxy.RequestSoapContext.Security.Tokens.Add(token);
就是这样!仅供参考,提供者是 Blackboard 实例。
And that's it! FYI, the provider is a Blackboard instance.