我正在研究一個WCF CustomBehavior插入BizTalk 2010發送端口以調用JSON/REST服務。 SendPort是WCF/Custom,綁定類型= webHttpBinding。錯誤「無法根據請求設置空或空方法。」在WCF CustomBehavior
我需要將四個頭添加到請求。
當我有這個代碼在我BeforeSendRequest方法:
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;
它給我這個錯誤:
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
當我離開的代碼的時候,我得到一個415回從合作伙伴的網絡服務,所以我知道我至少在那裏。
我在做什麼與此類似職位:How to add a custom HTTP header to every WCF call?