开发者

How to make ServiceActivationException thrown in the ASP.NET web server through to the browser?

I have a Silverlight client talking to a web server (which is, of course, ASP.NET application) using WCF.

Now, when the WCF security setup does not match the one defined in IIS, communication fails, of course. For instance, the SSL settings of the virtual directory may specify 开发者_如何学Gothat client certificate is to be ignored, but the WCF configuration may require the client certificate. This is a conflict. Trying to communicate using WCF from the Silverlight client to the web server results in the NotSupportedException, which is later wrapped in the ServiceActivationException thrown within the IIS worker process:

System.NotSupportedException occurred
  Message=The SSL settings for the service 'SslRequireCert' does not match those of the IIS 'Ssl'.
  Source=System.ServiceModel.Activation
  StackTrace:
       at System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateHttpsSettings(String virtualPath, Nullable`1& requireClientCertificate)
  InnerException: 

However, this exception is not being propagated to the browser. One of the catch statements executed during the stack unwinding (found in the method HostedHttpRequestAsyncResult.BeginRequest) checks the http method and if it is not GET swallows the exception completely:

catch (ServiceActivationException exception)
{ 
  if (string.Compare(GetHttpMethod(), "GET", StringComparison.OrdinalIgnoreCase) == 0)
  {
    if (exception.InnerException is HttpException)
    { 
      throw exception.InnerException;
    } 
    else 
    {
      throw; 
    }
  }

  SetStatusCode((int)HttpStatusCode.InternalServerError); 
  SetStatusDescription(HttpChannelUtilities.StatusDescriptionStrings.HttpStatusServiceActivationException); 
  CompleteOperation(null); 
}

(I used .NET Reflector to trace the execution)

Now, while the original exception contains a very accurate error description, the final exception is absolutely useless.

My question is there anything to do? Is it possible to make WCF use the GET method? Does it make any sense? And how are we supposed to troubleshoot issues like that if they are swallowed along the way?

Thanks a lot in advance.

EDIT1

I wish to emphasize that I have no problems of logging these errors on the web server side. I utilize the Factory attribute of the @ServiceHost metadata to define a custom ServiceHost type, where I can log errors in its OnOpen method. The problem is that I wish to see meaningful errors arriving to the browser.

EDIT2

A bit of context is due. I need to be able to troubleshoot logon failures. All of them are visible in the web server log. However, sometimes it is very convenient to be able to see the same errors on the client side, without the need to request the web server log file. Hence, all the logon failures are output to the debug console (viewable in DbgView) and the browser's log console. This makes troubleshooting easier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜