2016-08-17 45 views
0

我正在研究一個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?

回答

1

從一個同事,我改變了:

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

和它的工作...

的原因是,事實證明,當你有一個無效的「OperationName」時,那麼request.Headers.Action就有了來自BizTalk發送端口的整個CustomAction字符串:

<BtsActionMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <Operation Name="DELETE" Action="DELETE" /> 
    <Operation Name="GET" Action="GET" /> 
    <Operation Name="POST" Action="POST" /> 
</BtsActionMapping> 

我樣品這裏經過造型我的代碼: https://biztalkrest.codeplex.com/discussions/657185

上面的修復程序後,我恍然大悟到業務流程中的邏輯端口匹配「操作名稱」,果然,我有「郵報」而不是「POST」。 Ughhh ...很顯然,當OperationName與CustomAction操作不匹配時,BizTalk只是發送整個CustomAction XML塊到...驚人的...

下圖是我從「Post」發佈」。

enter image description here

相關問題