RequestInterceptor中的ProcessRequest永不结束[WCF]
问题描述:
因此,我使用的是Developer's Guide to the WCF REST Starter Kit,并且与RequestInterceptor有问题。我有指南显示的确切代码,但由于某种原因,该方法永远不会结束。RequestInterceptor中的ProcessRequest永不结束[WCF]
这是我的代码:
public override void ProcessRequest(ref RequestContext requestContext)
{
GenerateErrorResponse(requestContext, HttpStatusCode.Forbidden, "shit happens!");
}
public void GenerateErrorResponse(RequestContext context, HttpStatusCode statusCode, string errorMessage)
{
XElement response = XElement.Load(new StringReader(string.Format(ERROR_HTML, errorMessage)));
Message reply = Message.CreateMessage(MessageVersion.None, "action", response);
HttpResponseMessageProperty responseProp = new HttpResponseMessageProperty()
{
StatusCode = statusCode,
//StatusDescription = errorMessage
};
responseProp.Headers[HttpRequestHeader.ContentType] = "text/html";
reply.Properties[HttpResponseMessageProperty.Name] = responseProp;
context.Reply(reply);
context = null;
}
我的电话卡在context.Reply(答复);我不知道我在做什么错...任何抬头?
感谢
答
好吧,是我不好......这是一个简单的/愚蠢的问题。
首先有一个异常发生,我没有看到...一旦我添加了一个try catch和跟踪我发现我得到以下错误:“System.InvalidOperationException:此集合包含请求标头,不能包含指定的响应标题“。
寻找一点点接近后,我发现我加入HttpRequestHeader代替HttpResponseHeader ......我的坏:(
responseProp.Headers[HttpResponseHeader.ContentType] = "text/html";