473,545 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Exceptions with Web Services

I'm creating a Web service and a Windows Forms application to consume it.
My question is about throwing a custom exception inside the WebService.
Can that be done, and can the custom web service be handled in the Windows
Forms app?

For example, suppose in my WebService, I have the following exception
class:

'\\\\\
<Serializable() > _
Public Class WebServiceExcep tion
Inherits ApplicationExce ption <<<<<<< Is this correct?

'Code for exception class here

End Class
../////

And then within my web method:

'\\\\\
<WebMethod()> _
Public Sub SomeWebMethod()

If SomeCondition Then
Throw New WebServiceExcep tion
End If
End Sub
'/////
On the Windows Forms client, I can only trap for generic exceptions not my
custom exception type:

Try
WebService.Some WebMethod
Catch ex As WebServiceExcep tion <<<<<<<<< This doesn't work
'Handle it
End Try
Anyone know of a way to achieve this?

Thanks for any pointers

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Jul 21 '05 #1
1 1473
This seems to be a limitation of .NET SOAP implementation. Ideally things
should happen the way you're expecting (like they do in other SOAP
implementations ), especially if both sides are built by you.

However, typically you should derive your SOAP exceptions from
System.Web.Serv ices.Protocols. SoapException. This class has additional
properties you can set such as Actor, Code, Detail, Message when you throw
the exception at the server end.

Either ways, a SOAPException is raised on the client and you are left with
parsing the properties of this exception to figure out what really happened.
To go a step further, you could have a class that knows how to parse the
soap fault and raise the actual exception on the client provided, the client
is aware of that exception as well. Or maybe you could use SOAP Extensions
and do it that way.
--
Shiv R. Kumar
http://www.matlus.com
Jul 21 '05 #2

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

Similar topics

1
1290
by: Chris Dunaway | last post by:
I'm creating a Web service and a Windows Forms application to consume it. My question is about throwing a custom exception inside the WebService. Can that be done, and can the custom web service be handled in the Windows Forms app? For example, suppose in my WebService, I have the following exception class: '\\\\\ <Serializable()> _
2
2525
by: Matt | last post by:
Hello all, The app we are working on uses custom errors extensively to provide friendly error pages to users whilst logging the actual exceptions behind the scenes. However.... We are now having to integrate some Web services into the application using the existing architecture. These Web services are secured using Forms Authentication....
5
6934
by: Jon Skeet [C# MVP] | last post by:
I've run against a problem which I'm *sure* must be easy to solve - but I'm blowed if I can find the answer :( I have a web service which I want to require authentication. I need to authenticate using a database lookup, so Windows, Passport and Forms authentication are (as far as I can tell) no good to me. I don't need impersonation. I...
0
1479
by: Giulio | last post by:
Hi programmers, I'm quite new in this blog, I have a question concerning web services Soap Exceptions: I created a class MySoapException derived from SoapException, I add the references both server-side and client-side, and I tried to implement correctly serialization, I mean, the "ability" of a class to be used through a web services...
0
1912
by: Giulio | last post by:
Hi programmers, I'm quite new in this blog, I have a question concerning web services Soap Exceptions: I created a class MySoapException derived from SoapException, I add the references both server-side and client-side, and I tried to implement correctly serialization, I mean, the "ability" of a class to be used through a web services...
8
9201
by: Richard Collette | last post by:
When attempting to debug a webservice, I get the error: Cannot serialize member System.Exception.Data of type System.Collections.IDictionary, because it implements IDictionary. In reading about web services (http://msdn2.microsoft.com/en-us/library/ds492xtk.aspx), the documentation states that exceptions will automatically be handled as a...
3
5621
by: Tomsawyer2kin_hotmail | last post by:
Hi, I created a custom Exception Class as Public Class CSTException : Inherits System.ApplicationException ' required to over ride the base class method Sub New(ByVal ExceptionCode As AppExCodes) MyBase.New(CStr(ExceptionCode)) End Sub end class
3
3392
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own exception constructors? I've noticed that, f.ex., ArgumentException accepts null arguments without raising ArgumentNullException. Obviously, if nothing is...
5
4286
by: =?Utf-8?B?RGVlcGFrIFZpag==?= | last post by:
Hi, I an using Web Services as my business layer and wanted to throw custom exceptions from the web method based on some business logic. Now, when I make a custom exception class bu inheriting from SoapException class and throw it from a web method. I get below mentioned error message when I run that method: ...
0
7464
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7751
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.