Reputation: 5670
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
Upvotes: 1
Views: 8945
Reputation: 1075
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.
Upvotes: 3