exception responses to ASP.Net soap services

M

Mark

Hi...

How does one get an exception in a SOAP method call to get returned as a
SOAP error packet? I found several articles online that seemed to imply
wrapping it in a SoapException should result in proper handling but that
doesn't appear to be the case.

Throwing a SoapException from a web service method just leads to an http
status of 500 and no output at all.

Is there support in the framework for returning a soap exception packet, or
does one have to roll one's own?

Thanks
Mark
 
J

John Saunders

Mark said:
Hi...

How does one get an exception in a SOAP method call to get returned as a
SOAP error packet? I found several articles online that seemed to imply
wrapping it in a SoapException should result in proper handling but that
doesn't appear to be the case.

Throwing a SoapException from a web service method just leads to an http
status of 500 and no output at all.

Is there support in the framework for returning a soap exception packet,
or
does one have to roll one's own?

Any uncaught exception is translated into a SOAP Fault. That should always
happen.

Please create and post a small piece of code that reproduces the situation
where an exception is not returned as a SOAP Fault?
 
M

Mark

The simple Hello World example
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;

namespace WebService1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
throw new SoapException("boo hoo", SoapException.ServerFaultCode,
"http://tempuri.org/HelloWorld", new ApplicationException("Ha ha"));
return "Hello World";
}
}
}

produces :

HTTP/1.1 500 Internal Server Error
Server: ASP.NET Development Server/8.0.0.0
Date: Fri, 03 Oct 2008 16:25:39 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Content-Length: 250
Connection: Close

System.Web.Services.Protocols.SoapException: boo hoo --->
System.ApplicationException: Ha ha
--- End of inner exception stack trace ---
at WebService1.Service1.HelloWorld() in
C:\test\ConsoleApplication1\WebService1\Service1.asmx.cs:line 21

For example...

Thanks
Mark
 
J

John Saunders

Mark said:
The simple Hello World example
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;

namespace WebService1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
throw new SoapException("boo hoo", SoapException.ServerFaultCode,
"http://tempuri.org/HelloWorld", new ApplicationException("Ha ha"));
return "Hello World";
}
}
}

produces :

HTTP/1.1 500 Internal Server Error
Server: ASP.NET Development Server/8.0.0.0
Date: Fri, 03 Oct 2008 16:25:39 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Content-Length: 250
Connection: Close

System.Web.Services.Protocols.SoapException: boo hoo --->
System.ApplicationException: Ha ha
--- End of inner exception stack trace ---
at WebService1.Service1.HelloWorld() in
C:\test\ConsoleApplication1\WebService1\Service1.asmx.cs:line 21

How are you invoking the service? From the browser? That isn't using SOAP!
 
M

Mark

D'oh...

I'd tried the automatically-generated sample page, but as you said that was
in a browser. Then I tried telneting to the web service instance and sending
the post packet on the sample page, but I put the wrong number in for length.

In the case where the soap packet itself is the error (problem caused by
erroneous length), I was just getting back a status 500 and then the
connection closed.

When I got the length right, I see the soap error packet in the response.

Sorry for the false alarm - but thanks for answering.

Mark


John Saunders said:
Mark said:
The simple Hello World example
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;

namespace WebService1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
throw new SoapException("boo hoo", SoapException.ServerFaultCode,
"http://tempuri.org/HelloWorld", new ApplicationException("Ha ha"));
return "Hello World";
}
}
}

produces :

HTTP/1.1 500 Internal Server Error
Server: ASP.NET Development Server/8.0.0.0
Date: Fri, 03 Oct 2008 16:25:39 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Content-Length: 250
Connection: Close

System.Web.Services.Protocols.SoapException: boo hoo --->
System.ApplicationException: Ha ha
--- End of inner exception stack trace ---
at WebService1.Service1.HelloWorld() in
C:\test\ConsoleApplication1\WebService1\Service1.asmx.cs:line 21

How are you invoking the service? From the browser? That isn't using SOAP!
 
J

John Saunders

Mark said:
D'oh...

I'd tried the automatically-generated sample page, but as you said that
was
in a browser. Then I tried telneting to the web service instance and
sending
the post packet on the sample page, but I put the wrong number in for
length.

In the case where the soap packet itself is the error (problem caused by
erroneous length), I was just getting back a status 500 and then the
connection closed.

When I got the length right, I see the soap error packet in the response.

Sorry for the false alarm - but thanks for answering.

I'm glad you got it worked out.

For your information, I prefer to write a client to test a service. Such a
client would have shown you that you are always getting an exception if an
exception was thrown.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top