简体   繁体   中英

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.

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. 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. This exception eventually gets to the UI in the form a MessageSecurityException .

Is there any way to suppress this so the message inspector's AfterReceiveReply still fires? or is there somewhere else I can access the entire raw response?

Thanks!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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