2016-04-21 40 views
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 
     } 
    } 
} 
+1

「WebContentTypeMapper」的意圖是**指定映射__incoming消息___的內容類型的格式。**所以你肯定會收到請求。 –

回答

0

由於Amit Kumar Ghosh解釋說映射僅用於傳入消息,因此不再需要答案。我只是想知道爲什麼處理請求後調用映射器。

相關問題