Within my WebApi controller, I am trying to call an .asmx
SOAP Service.
I used VS2015 to generate the SoapClient proxy as a Service Reference.
My main problem is that I need to set the Authorization header to contain a Bearer token.
I thought I had a solution, using @SimonRC's answer here. My code looks like this:
using (OperationContextScope scope = new OperationContextScope(_client.InnerChannel))
{
var httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Bearer blahblahblah";
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
string packetData = await _client.GetPacketAsync(packetNumber, packetDate.ToString("ddMMMyy"));
response = new Packet()
{
packet = packetData
};
return response;
}
This works great when I debug in VS2015, but when I deploy my WebApi to Azure I'm getting this error:
The value of OperationContext.Current is not the OperationContext value installed by this OperationContextScope.
I'm looking for either (a) an solution to resolve this error, or (b) an alternate way to set the Authorization header to contain a Bearer token.