I'm working on a WCF CustomBehavior that plugs into a BizTalk 2010 SendPort in order to call a JSON/REST service. The SendPort is WCF/Custom with Binding Type=webHttpBinding.
I need to add the four headers to the request.
When I include this code in my BeforeSendRequest method:
var newHttpRequestMessageProperty = new HttpRequestMessageProperty
{
Method = request.Headers.Action,
QueryString = string.Empty,
SuppressEntityBody = false,
};
newHttpRequestMessageProperty.Headers.Add("X-ST-PartnerID", partnerIDFromSSO);
newHttpRequestMessageProperty.Headers.Add("X-ST-Token", tokenIDFromSSO);
newHttpRequestMessageProperty.Headers.Add("X-ST-AuthType", "TOKEN");
newHttpRequestMessageProperty.Headers.Add("Accept-Language", "EN");
request.Properties[HttpRequestMessageProperty.Name] = newHttpRequestMessageProperty;
It gives me this error:
System.ArgumentException: Cannot set null or blank methods on request.
Parameter name: value
Server stack trace:
at System.Net.HttpWebRequest.set_Method(String value)
at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.PrepareHttpSend(Message message)
at System.ServiceModel.Channels.HttpOutput.BeginSendCore(HttpResponseMessage httpResponseMessage, TimeSpan timeout, AsyncCallback callback, Object state)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.SendWebRequest()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.OnGetWebRequestCompleted(IAsyncResult result)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.BeginSendRequest(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)
at System.ServiceModel.Dispatcher
When I leave that code out, I get a 415 back from the partner's web service, so I know that I'm getting there at least.
What I'm doing is similar to this post: How to add a custom HTTP header to every WCF call?