我已经成功地创建了一个WS客户端,它在不使用身份验证时工作正常。
但是,服务器(WebSphere)现在需要添加一个ws安全用户名令牌,我很难做到这一点。得到的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的WSE3.0SDK,并在Visual 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进行调查,但到目前为止,我还无法启动和运行任何东西。
任何提示都是非常感谢的,因为我似乎在网上找不到任何好的菜谱。
谢谢!
发布于 2010-01-26 14:41:55
让它正常工作,不幸的是,在阅读wsanville的伟大答案之前。
为了帮助其他人,我发布了我需要做的所有步骤,以便让它与Visual 2005一起工作:
YourWsNameHttpServiceWse。这与运行wsewsdl3.exe本质上是一样的SetClientCredential。最后,我在代码中完成了几乎所有的工作,而不是依赖使用我的C# DLL构建的配置文件。代码最后看起来是这样的:
FooBarHttpServiceWse wse = new FooBarHttpServiceWse();
wse.SetClientCredential(new UsernameToken(
"username",
"password",
PasswordOption.SendPlainText));
wse.SetPolicy(new FooBarPolicy());
wse.CallSomeServerFunction(yourRequest)我制定了自己的政策,看起来是这样的:
using Microsoft.Web.Services3.Design;
// ...
public class FooBarPolicy : Policy
{
public FooBarPolicy()
{
this.Assertions.Add(new UsernameOverTransportAssertion());
}
}最后,WebSphere服务器响应说,不存在表示消息寻址属性的必需标头,并且检查传出消息(使用费德勒) --我从服务器看到SOAP错误--表明Action丢失了。
我试图自己设置wsa:Action元素,但没有成功:
using Microsoft.Web.Services3.Addressing;
// ...
wse.RequestSoapContext.Addressing.Action = new Action("CallSomeServerFunction");问题是,即使我设置了一个动作,当它通过电线发送时,它是空的。结果,我不得不打开WSE代理类并在那里编辑一个属性:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute(
"---Edit this to set wsa:Action---",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
// ...
public SomeServerFunction(...)在那之后,一切都很顺利。
发布于 2010-01-26 13:06:32
确保您的代理类继承自Microsoft.Web.Services3.WebServicesClientProtocol。
您可以通过更改代理类本身,或者使用wsewsdl3.exe和/type:webClient开关通过命令行生成代理类来实现这一点。
然后,您可以这样传递凭据:
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Security.Tokens;
using Microsoft.Web.Services3.Security;
.
.
.
WS.FooResultHttpService ws = new WS.FooResultHttpService();
ws.RequestSoapContext.Security.Tokens.Add(new UsernameToken("blah", "blah", PasswordOption.SendPlainText));这就是我过去为在Studio 2008中运行WSE3.0所做的事情。希望这能有所帮助。
https://stackoverflow.com/questions/2139190
复制相似问题