2

I am using SoapException to handle invalid inputs and all other kind of exception handling in my web service. It's working fine and I am able to format and return proper information to client. I am following a method similar to the one explained here http://www.codinghorror.com/blog/2004/08/throwing-better-soap-exceptions.html

Now I want to change the response code it returns when a SoapException happens (ResponseCode: 500 Internal Server Error).

Following is the default response code am getting in addition to my own custom XML data when a SoapException occurs. I want to change the ResponseCode to 200.. Is it possible and how?

ResponseCode: 500 (Internal Server Error)  
Connection:Close  
Content-Length:494  
Cache-Control:private  
Content-Type:text/xml; charset=utf-8  
Date:Tue, 25 Jan 2011 06:59:30 GMT  
Server:ASP.NET Development Server/8.0.0.0  
X-AspNet-Version:2.0.50727
shA.t
  • 16,580
  • 5
  • 54
  • 111
Ansar Muhammad
  • 1,238
  • 5
  • 25
  • 45
  • found the answer ((System.Web.HttpContext)(System.Runtime.Remoting.Messaging.CallContext.HostContext)).Response.StatusCode = 200; – Ansar Muhammad Jan 31 '11 at 05:22
  • 2
    @Ariz: if that's the solution you chose, then you chose to violate the SOAP standard. The code has to be 500. – John Saunders Feb 01 '11 at 20:37
  • Since some browsers do not forward exception content to flash which is consuming the webmethod, I also want to change the statusCode to 200. However, the solution does not work for me. `((System.Web.HttpContext)(System.Runtime.Remoting.Messaging.CallContext.HostCont‌​ext)).Response.StatusCode = 200; throw new SoapException();` still returns response code 500 – Smalcat Jan 16 '13 at 11:31

1 Answers1

2

In support of John Sauders' word of warning above, according to WS-I Basic profile:

"R1126 An INSTANCE MUST use a "500 Internal Server Error" HTTP status code if the response message is a SOAP Fault."

http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html#refinement16488480

Rob Potter
  • 948
  • 6
  • 28