How to add security header to a SOAP message?

后端 未结 2 945
猫巷女王i
猫巷女王i 2020-12-05 21:37

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: Inco

2条回答
  •  失恋的感觉
    2020-12-05 22:02

    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

    • Get WSE 2.0
    • Add the Web Reference to the project
    • In the Web Reference proxy implementation:

    Replace

    public partial class UserWS : System.Web.Services.Protocols.SoapHttpClientProtocol
    

    by

    public partial class UserWS : Microsoft.Web.Services2.WebServicesClientProtocol
    
    • Before calling the Web Service:

    Set the authentication info

    UsernameToken token = new UsernameToken("user", "pwd", PasswordOption.SendPlainText);
    yourProxy.RequestSoapContext.Security.Tokens.Add(token);
    

    And that's it! FYI, the provider is a Blackboard instance.

提交回复
热议问题