473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Exceptions thrown by Web Services

When a Web Service throws an exception to the caller/client, the
exception is always cast to SoapException regardless of the actual type
of the exception thrown. In such a scenario, how would you think it is
appropriate for a Web services client to determine the exact type of
exception?
Consider this example.
CLIENT
class Client
{
[STAThread]
static void Main(string[] args)
{
using(localhost.ExceptionThrowerService ets = new
ExceptionCatcher.localhost.ExceptionThrowerService ())
{

try
{
ets.throwCustomException();
}
catch(System.Exception e)
{
/*How would you determine here whether the type of e is
MyCustomException or some other one
Given that MyCustomException is given inside the Web service.*/
Console.WriteLine(e.GetType().ToString());
}
Console.ReadLine();
}
}
}







SERVER
namespace ExceptionThrower
{
public class ExceptionThrowerService : System.Web.Services.WebService
{

[WebMethod]
public void throwCustomException()
{
Trace.WriteLine("Throwing custom exception now.");
throw new MyCustomException();
}
} //End of class ExceptionThrower
public class MyCustomException: System.Exception
{
private string mDetail = "I am the best guy.";

public MyCustomException()
{
mDetail = "I am *still* the best guy.";
}

public MyCustomException(string lDetail)
{
this.Detail += ("\n" + lDetail);
}

public string Detail
{
get
{
return mDetail;
}
set
{
mDetail = value;
Trace.WriteLine("Setting the value of mDetail...");
}
}

}//End of class MyCustomException

}

Feb 24 '06 #1
2 1638
Wouldn't the SoapException.InnerException contain the details you're
looking for?

If you're working with your own custom Exceptions, make sure to mark
them Serializable and implement the protected Exception(
SerializationContext, SerializationInfo ) constructror (just call the
base constructor..)

HTH
Andy

Feb 24 '06 #2
Hi Andy,

I've done what you said, but it doesn't get accross the boundaries yet.
Did you mean this?
SERVER
protected
MyCustomException(System.Runtime.Serialization.Ser ializationInfo si,
System.Runtime.Serialization.StreamingContext sc): base(si, sc)
{
//nothing
}

CLIENT
try
{
ets.throwCustomException();
}
catch(System.Exception e)
{
if (e.InnerException != null)
Console.WriteLine(e.InnerException.ToString());
else
Console.WriteLine("e.InnerException is null");
}

Feb 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
9
by: Marty McDonald | last post by:
If I invoke a web service, and it throws an exception, I can see the exception if the client app is a .Net app. However, if the client app is not a .Net app, I only receive the HTTP 500 error. I...
1
by: Diego F. | last post by:
I use to show the error messages that I get in a try block. try { ... } catch (Exception ex) { ... (ex.Message); }
4
by: John | last post by:
I have WSDL file with <wsdl:fault> element. When I use Websphere WSAD to generate Java proxy classes from WSDL, I am able to see the custom exception classes that correspond to the <wsdl:fault>...
6
by: Mikus Sleiners | last post by:
Is there any way to enable exception throws in VS 2005, that occur during binding operations? I am upset that i can't see exceptions that are thrown during binding operations. It's very hard to...
6
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
8
by: Olivier BESSON | last post by:
Hello, VB.NET 1.1 IIS 6 I'm developping a winform client app of a web service of mine. I used to set the IDE with "halt in debugger" on "common language runtime exceptions". Every time i...
1
by: =?Utf-8?B?TmVpbEw=?= | last post by:
I have a Windows C# application that is trying to invoke a remote WebService (both mine). My problem is that trying to call the VSNet2005 generated async methods on the service can throw exceptions...
3
by: John Skandar | last post by:
I've found a free WebService on the net for a currency converter and have created a class to use it with the WSDL tool. I call the WebService method asynchronously: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.