WebContentTypeMapper:确定我是否正在接收或响应请求

时间:2016-04-21 09:24:50

标签: c# web-services

我有一个使用WebContentTypeMapper的Web服务,以便在我的界面中允许不同的签名。现在我发现对于单个POST请求,WebContentTypeMapper被调用了3次。处理我的OperationContract之前和之后的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
        }
    }
}

1 个答案:

答案 0 :(得分:0)

由于Amit Kumar Ghosh解释说映射仅用于传入消息,因此不再需要答案。我只是想知道为什么在处理请求后调用mapper。