How to pass bearer token in SOAP client request

144 Views Asked by At

I am making call to SOAP based API. I need to pass a bearer token for Authorization. But I am unable to figure out how to pass it.

Below is how I make API call

SoapServiceClient cs = new SoapServiceClient (); //initializing SoapHttpClientProtocol
cs.Timeout = 99999999; 
cs.Url = "https://gateway.client.com/v1"; //API endpoint
object response = cs.CreateSession(createSessionRequest); //Calling one of its API and assigning the response xml in response object. CreateSession is client's method in wsdl.

//how to set bearer token, something like below:
cs.Authorization = "Bearer" + generatedtoken; 
1

There are 1 best solutions below

2
Tiny Wang On

I'm not very sure about it. I followed this document to create a SOAP web service in .net 7, then I can get the API response from postman like below.

enter image description here

Then I tried to use httpClient to call it in the .net 7 web application. And I found I'm able to get the response. Then I noticed that in .net 5+, we have corewcf which supports Http & NetTCP transports.

enter image description here