0
我有一個Web服務使用WebContentTypeMapper來允許我的界面中有不同的簽名。現在我發現WebContentTypeMapper對於單個POST請求被調用了3次。處理我的OperationContract之前和之後2次。WebContentTypeMapper:確定我是否正在接收或響應請求
如何確定WebContentTypeMapper內是否收到請求或已經響應?
using System;
using System.ServiceModel.Channels;
using System.Web;
public class RawContentTypeMapper : WebContentTypeMapper
{
public override WebContentFormat GetMessageFormatForContentType(string contentType)
{
string pathInfo;
try
{
pathInfo = HttpContext.Current.Request.PathInfo;
}
catch (NullReferenceException)
{
pathInfo = null;
}
switch (pathInfo)
{
case "/rest/myoperationcontract1":
return WebContentFormat.Raw; // This allows to define an operationcontract with parameter of type Stream where we can read the body of the request.
default:
return WebContentFormat.Default; // No change to default behavior
}
}
}
「WebContentTypeMapper」的意圖是**指定映射__incoming消息___的內容類型的格式。**所以你肯定會收到請求。 –