1

I am trying to connect to a SOAP API using C#. The API I use insists that I need to authenticate each API call with an OAuth Token. I have implemented the OAuth system and got the token I needed, But I am not sure how to Append it to the SOAP Call I am making. So I trid something like this

       var soapClient = new ReturnClient();
    soapClient.ClientCredentials.UserName.UserName = "MyToken";
    soapClient.ClientCredentials.UserName.Password = "MyToken";
    var rrr = new RetrieveReturnRequest {RetrieveReturnRequestWrapper = xElem2};
    var response = soapClient.RetrieveReturn(rrr);

But this does not works and throws System.ServiceModel.CommunicationException:. Can anyone pointout what's the correct way to Authenticate a SOAP call with Access Token

None
  • 5,582
  • 21
  • 85
  • 170
  • What message you get in the Exception? – Chetan Jan 31 '18 at 03:31
  • @ChetanRanpariya An error occurred while making the HTTP request to https://apidomain/returns/. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the – None Jan 31 '18 at 03:32

1 Answers1

3

Typically, when you use OAuth, you need to pass the "token" using an HTTP Header. For OAuth2 and a bearer token, you will need to pass it in the Authorization HTTP header.

requestMessage.Headers["Authorization"] = "Bearer TOKEN_VALUE_HERE";

See this link for more details on how to pass an HTTP Header in a SOAP Client.

mtheriault
  • 1,065
  • 9
  • 21