MessageSecurityException

MessageSecurityException

本文介绍了服务器返回HTTP 401时如何获取WCF FaultException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个用于一组Web服务的基于WCF的测试工具客户端.测试客户端使我可以查看去往和来自服务的原始请求和响应.Message Inspector端点行为用于提取"原始请求和响应消息,并将其保存以供以后在UI中显示.

I have a WCF based test harness client for a set of web services. The test client allows me to see raw requests and responses going to and from the services. A Message Inspector endpoint behavior is used to "pick off" the raw requests and response messages and save them for later display in the UI.

这很好用,除了通过无效凭证的用例.服务器返回HTTP 401以及包含故障详细信息的SOAP错误.这以多种方式伤害了我:

This works great, except for the use case where invalid credentials are passed. The server returns an HTTP 401 along with a SOAP fault containing details of what happened. This hurts me in a couple ways:

  1. 在客户端上,这显示为 MessageSecurityException 而不是 FaultException ,因此我无法从故障中获取详细信息.
  2. 此异常似乎阻止了消息检查器上的 AfterReceiveReply 事件处理程序被触发,因此我无权访问原始响应.
  1. On the client this shows up as a MessageSecurityException not a FaultException, so I can't get the details from the fault.
  2. This exception appears to prevent the AfterReceiveReply event handler on my message inspector from firing, so I have no access to the raw response.

有什么办法可以处理这种情况,以使SOAP错误作为FaultException通过,并允许我的消息检查器处理响应,而不管返回的HTTP状态代码如何?

Is there any way I can handle this case so that the SOAP fault comes through as a FaultException and allow my message inspector to handle responses regardless of the HTTP status code that is returned?

谢谢!

推荐答案

您不能.如果在服务器端代码中 发生了.NET异常并被捕获,则只会得到 FaultException .

You cannot. You will only get a FaultException if a .NET exception occured in the server side code and has been caught.

HTTP 401是未经授权的访问"-您甚至会在到达服务器代码之前得到该异常->这将始终是 MessageSecurityException -绝不会是 FaultException (也无法将其神奇地转化为FaultException).

HTTP 401 is "Access in unauthorized" - you'll get that exception before you even reach the server code --> this will always be a MessageSecurityException - never a FaultException (and there's no way to magically turn that into a FaultException, either).

在执行甚至到达服务器代码之前发生的任何异常(诸如 EndpointNotFoundException TimeoutException 之类的东西)都不会出错.

Any exception that occurs before the execution even reaches the server code (things like EndpointNotFoundException or TimeoutException) are never fault exceptions.

所有WCF特定的异常都来自一个通用基类,但是- CommunicationException .因此,也许您可​​以将其作为备用.

All the WCF specific exceptions descend from a common base class, however - CommunicationException. So maybe you can handle that as a fallback.

这篇关于服务器返回HTTP 401时如何获取WCF FaultException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:04