开发者

calling a secure service using a service reference

开发者 https://www.devze.com 2023-01-17 01:23 出处:网络
Th开发者_如何学Goere is an external secure service that I am consuming in my .net class by making a web reference to it and passing it the username token like so:

Th开发者_如何学Goere is an external secure service that I am consuming in my .net class by making a web reference to it and passing it the username token like so:

MyWebService objWS = new MyWebService();
UsernameToken token = new UsernameToken("User","Password", PasswordOption.SendPlainText);
objWS.RequestSoapContext.Security.Timestamp.TtlInSeconds = 60;
objWS.RequestSoapContext.Security.Tokens.Add(token);
objWS.RequestSoapContext.Security.MustUnderstand = false;

when I make service reference to the same service url and try to pass in the username and password using ClientCredentials it fails.

I have no idea about the external service. Any idea what could be wrong?

Thanks for your time...


Are you calling the service over https? The server may require a client certificate. I found this example usage of. UsernameToken


The solution was to install WSE3 and in the proxy generated inherit from Microsoft.Web.Services3.WebServicesClientProtocol instead of the default System.Web.Services.Protocols.SoapHttpClientProtocol.

Then the service proxy object would get the Security property.

objWS.RequestSoapContext.Security

which I can then use to pass in the UsernameToken.

This is a hack and I have not found a better way to do it yet. Regenerating the proxy will always involve that extra step of having to manually edit the proxy again, as above.

0

精彩评论

暂无评论...
验证码 换一张
取 消