NealWalters NealWalters - 1 year ago 185
reST (reStructuredText) Question

Error "Cannot set null or blank methods on request." in WCF CustomBehavior

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 header to every WCF call?

Answer Source

From a co-worker, I changed:

     //Method = request.Headers.Action,
     Method = "POST",

and it worked...

The reason was, it turns out that when you have an invalid "OperationName", then request.Headers.Action had the entire CustomAction string from the BizTalk sendport:

<BtsActionMapping xmlns:xsi="" xmlns:xsd="">
  <Operation Name="DELETE" Action="DELETE" />
  <Operation Name="GET" Action="GET" />
  <Operation Name="POST" Action="POST" />

I'm modeling my code after sample here:

After the above fix, it dawned on me to match the "Operation Name" in the orchestration's logical port, and sure enough, I had "Post" instead of "POST". Ughhh... So apparently when the OperationName doesn't match the CustomAction operations, BizTalk just sends the entire CustomAction XML block on through... Amazing...

In picture below is where I changed from "Post" to "POST".

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download