Web服务请求认证 [英] Web service request authentication

查看:124
本文介绍了Web服务请求认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在被真正坚持在这里,所以我决定要问你的帮助。



昨天,我一直在问,以帮助使用Web服务,得到了网址到WSDL,用户证书才能使用。
我从来没有真正过任何与网络服务,但有关于他们的总体思路,看到我想举几个例子不能说不好。很显然,我错了,因为我现在我卡住。



一切似乎都很正常,已经生成了代理类(或客户),建立请求和发送它们的也没关系,除了认证的一部分。这点我们似乎无法弄清楚如何做到



使用:

  client.ChannelFactory.Credentials.UserName.UserName =名为myusername; 
client.ChannelFactory.Credentials.UserName.Password =输入mypassword;



似乎并没有工作。 (当我检查了client.Endpoint.Binding.CreateBindingElements(returbed的BindingElementCollection)没有SecurityBindingElement)



我试着这样做的其他许多方面,但我想我失去了一些东西基本和缺乏文件建立是不是真的帮助任



所以现在的问题是:我如何制作时发送的用户名和密码?调用Web服务,使用WCF



编辑:
只是为了澄清,请求应包含类似于此:

 < WSSE:安全的xmlns:WSSE =htt​​p://docs.oasis-open.org/wss/2004/ 01 /绿洲-200401-WSS-wssecurity-secext-1.0.xsdsoapenv:mustUnderstand属性=1> 
< WSSE:用户名令牌的xmlns:WSU =htt​​p://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsdWSU:ID = 用户名令牌-25763165>
< WSSE:用户名>用户名< / WSSE:用户名>
< WSSE:密码TYPE =htt​​p://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest> 1DiaGTkOLk / CZhDaEpbkAaKRfGw =< / WSSE:密码>
< WSSE:随机数> 6ApOnLn5Aq9KSH46pzzcZA ==< / WSSE:随机数>
< WSU:创建> 2009-05-13T18:59:23.309Z< / WSU:创建>
< / WSSE:用户名令牌>
< / WSSE:安全和GT;


解决方案

我有同样的问题。取而代之的是自定义的令牌序列化我用了一个 MessageInspector 添加正确的的UsernameToken BeforeSendRequest 方法。然后我用一个自定义的行为应用修复。



整个过程记录(用示范项目)在我的博客文章支持在WS-I Basic Profile的密码摘要WCF客户端代理。或者,你可以阅读 PDF



如果你想通过该溶液中,跟随我的进步,你会发现它在计算器上标题为的与WS-Security的用户名令牌PasswordDigest认证方案错误WCF客户端耗时2轴Web服务


We're being really stuck here so I decided to ask your help.

Yesterday I've been asked to help to consume a web service, got the URL to the WSDL, and the user credentials to use. I've never really had anything to do with web services, but having a general idea about them and seeing a few examples I thought it can't be that bad. Obviously I was wrong as I'm stuck now.

Everything seems to be fine, the proxy class (or client) has been generated, building up requests and sending them are fine too, apart from the authentication part. Which we can't seem to figure out how to do.

Using the:

client.ChannelFactory.Credentials.UserName.UserName = "myusername";
client.ChannelFactory.Credentials.UserName.Password = "mypassword";

doesn't seem to work. (When I check the BindingElementCollection returbed by the client.Endpoint.Binding.CreateBindingElements() there's no SecurityBindingElement)

I've tried so many other ways of doing it, but I think I'm missing something basic and the lack of documentaion is not really helping either.

So the question is: How do I send the username and password when making a call to a web service, using WCF?

Edit: Just to clarify, the request should contain something similar to this:

 <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
     <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-25763165">
        <wsse:Username>username</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">1DiaGTkOLk/CZhDaEpbkAaKRfGw=</wsse:Password>
        <wsse:Nonce>6ApOnLn5Aq9KSH46pzzcZA==</wsse:Nonce>
        <wsu:Created>2009-05-13T18:59:23.309Z</wsu:Created>
     </wsse:UsernameToken>
  </wsse:Security>

解决方案

I had the same problem. Instead of the custom token serializer I used a MessageInspector to add the correct UsernameToken in the BeforeSendRequest method. I then used a custom behavior to apply the fix.

The entire process is documented (with a demo project) in my blog post Supporting the WS-I Basic Profile Password Digest in a WCF client proxy. Alternatively, you can just read the PDF.

If you want to follow my progress through to the solution, you'll find it on StackOverflow titled, "Error in WCF client consuming Axis 2 web service with WS-Security UsernameToken PasswordDigest authentication scheme":

这篇关于Web服务请求认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆