简体   繁体   English

服务器返回HTTP 401时,如何在WCF中获取消息/响应正文?

[英]How can I get the message/response body in WCF when server returns an HTTP 401?

I have a WCF client test harness where I'm using a "client message inspector" endpoint behavior to "pick off" raw requests and response messages going to and from a service and save them for later display in the UI. 我有一个WCF客户端测试工具,我在其中使用“客户端消息检查器”端点行为来“拾取”与服务之间的原始请求和响应消息,并保存它们以供以后在UI中显示。

This works great, except for the use case where invalid credentials are passed (Basic Authentication). 除通过无效凭证(基本身份验证)的用例外,这非常有用。 The server returns an HTTP 401 along with a SOAP fault in the body containing details of what happened. 服务器在主体中返回HTTP 401以及SOAP错误,其中包含发生的事件的详细信息。 I have no control over the service, so this behavior cannot be changed. 我无法控制该服务,因此无法更改此行为。

Because the HTTP 401 is returned as a WebException , my message inspector never fires and I can't get to the raw response. 因为HTTP 401是作为WebException返回的,所以我的消息检查器永远不会触发,并且我无法获得原始响应。 This exception eventually gets to the UI in the form a MessageSecurityException . 该异常最终以MessageSecurityException的形式进入UI。

Is there any way to suppress this so the message inspector's AfterReceiveReply still fires? 有什么方法可以抑制这种情况,以便消息检查器的AfterReceiveReply仍然触发? or is there somewhere else I can access the entire raw response? 还是我可以访问整个原始响应的其他地方?

Thanks! 谢谢!

catch (WebException e)
{
    resp = (HttpWebResponse)e.Response;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM