WebContentTypeMapper:确定我是否正在接收或响应请求
本文关键字:响应 请求 是否 WebContentTypeMapper | 更新日期: 2024-10-25 11:12:58
我有一个使用WebContentTypeMapper的Web服务,以便在我的界面中允许不同的签名。现在我发现WebContentTypeMapper对于单个POST请求被调用了3次。在处理我的运营合同之前和之后 2 次。
如何在 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
}
}
}
由于Amit Kumar Ghosh解释说映射仅用于传入消息,因此不再需要答案。我只是想知道为什么在处理请求后调用映射器。