Throwing custom exceptions in web services using VS.Net

G

Gian U. Uy

I created a custom exception for my web service using VS.Net and it's
ASP.Net web service tools. Its base class derived from System.Exception and
I have a WinForm client that references the web service. But when I
referenced my Web Service, it did not pick up our custom exception class so
that the application could catch the exception in its actual class not by
the System.Exception class.

Is this possible?
 
D

Dave Beauchemin [MVP]

The way the .NET Framework currently works with web services (by default) is
to wrap web service exceptions in a SOAP exception. This is for standards
compliance, because the SOAP recommendation requires that exceptions or
errors be wrapped appropriately. If your web service were to communicate
with other applications (think interoperability), this would be the desired
effect.

Unfortunately, when working in a Microsoft-only environment, this can be
somewhat annoying. I've found that the best work-around to this is to create
a custom class which extracts the actual error and throws the base exception
in the callee application (which in your case would be the custom
exception).

Ultimately, the best place for custom exceptions is in your WinForms
application, not in the web service, IMHO.
--


Dave Beauchemin
Microsoft MVP, MCP
www.webdotmag.com
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top