473,785 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inherit from soapException

Hi

Im trying to create a custom Exception Hierachy for an Asp.net application.

Some of my exceptions should iherit from soapException like

MyCustomWebServ iceException : soapException
{
blabla
}

Anyone have som guidelines for this? The normal rule of emplementing the
three default constructors of course dosnt count, since he they doesnt
excitst.

Google gives my nothing in this subject.

Hope someone can cheer me up :)

Reagards
Anders, DK

Nov 17 '05 #1
9 3168
Example:
MyCustomWebServ iceException : soapException
{
private string _MyCustomProper ty;
public string MyCustomPropert y
{
get
{
return _MyCustomProper ty;
}
}
public MyCustomWebServ iceException(st ring message,
XmlQualifiedNam e code, string CustomParameter )
: base(string message, XmlQualifiedNam e code)
{
_MyCustomProper ty = CustomParameter ;
}
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Flare" <pl*@askforit.c om> wrote in message
news:OK******** *****@TK2MSFTNG P11.phx.gbl...
Hi

Im trying to create a custom Exception Hierachy for an Asp.net application.
Some of my exceptions should iherit from soapException like

MyCustomWebServ iceException : soapException
{
blabla
}

Anyone have som guidelines for this? The normal rule of emplementing the
three default constructors of course dosnt count, since he they doesnt
excitst.

Google gives my nothing in this subject.

Hope someone can cheer me up :)

Reagards
Anders, DK

Nov 17 '05 #2
Thx :)

But. When i trow MyCustomWebServ iceException i have problems. I cant catch
my exception as MyCustomWebServ iceException, only soapException. And thats a
big problem, since My error message at the client look somthing like this.

-----> IN DANSIH SORRY BUT NOT IMPORTANT.
Elsam.Turabs.Cl assLibraries.Tu rabsException.T urabsWebService Exception:
Calculation error---> System.DivideBy ZeroException: Calculation error. at
WebServiceExp.S ervice1.HelloWo rld() in
c:\inetpub\wwwr oot\webservicee xp\service1.asm x.cs:line 58 --- Slut på
staksporing af indre undtagelser --- at WebServiceExp.S ervice1.HelloWo rld()
in c:\inetpub\wwwr oot\webservicee xp\service1.asm x.cs:line 66
------>

My Message "Calculatio n error" is in the message besides lots og junk.

So final qusiton: Why can't i catch my custom SoapException?

The WS:
---------------
[WebMethod]
public void HelloWorld()
{
try
{
int y = 0;
int t = 1 / y ;
}
catch(System.Di videByZeroExcep tion DivideExp)
{
TurabsWebServic eException TurDBExp = new
TurabsWebServic eException("Cal culation
error",System.W eb.Services.Pro tocols.SoapExce ption.ServerFau ltCode,DivideEx p
);

throw(TurDBExp) ; //Rethrow to client
}

The client:
----------
Exp.Service1 a = new WSExp.Service1( );

try
{
a.HelloWorld();
}
catch(System.We b.Services.Prot ocols.SoapExcep tion et)
{
Label1.Text = et.Message;
}


Nov 17 '05 #3
You can only catch the Exception that was thrown. If you create a Custom
Exception class, your app will have to throw it. For example, your app might
catch the SoapException, use that to create an instance of your Custom
Exception class, and then throw that. I'm not sure what exactly you're
trying to do with all this, so that' about all I can tell you.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Flare" <pl*@askforit.c om> wrote in message
news:e1******** ******@TK2MSFTN GP10.phx.gbl...
Thx :)

But. When i trow MyCustomWebServ iceException i have problems. I cant catch
my exception as MyCustomWebServ iceException, only soapException. And thats a big problem, since My error message at the client look somthing like this.

-----> IN DANSIH SORRY BUT NOT IMPORTANT.
Elsam.Turabs.Cl assLibraries.Tu rabsException.T urabsWebService Exception:
Calculation error---> System.DivideBy ZeroException: Calculation error. at
WebServiceExp.S ervice1.HelloWo rld() in
c:\inetpub\wwwr oot\webservicee xp\service1.asm x.cs:line 58 --- Slut på
staksporing af indre undtagelser --- at WebServiceExp.S ervice1.HelloWo rld() in c:\inetpub\wwwr oot\webservicee xp\service1.asm x.cs:line 66
------>

My Message "Calculatio n error" is in the message besides lots og junk.

So final qusiton: Why can't i catch my custom SoapException?

The WS:
---------------
[WebMethod]
public void HelloWorld()
{
try
{
int y = 0;
int t = 1 / y ;
}
catch(System.Di videByZeroExcep tion DivideExp)
{
TurabsWebServic eException TurDBExp = new
TurabsWebServic eException("Cal culation
error",System.W eb.Services.Pro tocols.SoapExce ption.ServerFau ltCode,DivideEx p );

throw(TurDBExp) ; //Rethrow to client
}

The client:
----------
Exp.Service1 a = new WSExp.Service1( );

try
{
a.HelloWorld();
}
catch(System.We b.Services.Prot ocols.SoapExcep tion et)
{
Label1.Text = et.Message;
}

Nov 17 '05 #4
> You can only catch the Exception that was thrown. If you create a Custom
Exception class, your app will have to throw it. For example, your app might catch the SoapException, use that to create an instance of your Custom
Exception class, and then throw that. I'm not sure what exactly you're
trying to do with all this, so that' about all I can tell you.


Its hard to explain so ill try to exaplin it otherwise :)

I have an CustomSoapExcep tion wich inherit from SoapException.

To the CustomSoapExcep tion i Eg. add a property MyCustomPropert y.

Now I have extended my new SoapException compared to the baseexception.

Now i catch _some_ exeption in my webservice, eg a dberror. I create an
instanse of CustomSoapExcep tion and set the MyCustomPropert y to something
and rethrow this CustomSoapExcep tion to the client....right ?

But here is my CORE problem. How (can i?) do i access the MyCustomPropert y
on my client. Because CustomSoapExcep tion is downcastet to an ordinary
SoapException.. ...and MyCustomPropert y is gone.

AND becauase CustomSoapExcep tion is no longer an CustomSoapExcep tion on the
client i can't catch it as CustomSoapExcep tion .

Was that more clear?
Hope so anyway.
Anders

Nov 17 '05 #5
SF
Just a guess: The CustomSoapExcep tion is not "downcasted ", it is wrapped in
a SoapException.
If so, catch the SoapException on the client and rethrow its innerexception
(or just cast the inner
exception to CustomSoapExcep tion and access your custom property)

"Flare" <pl*@askforit.c om> wrote in message
news:#4******** *****@TK2MSFTNG P10.phx.gbl...
You can only catch the Exception that was thrown. If you create a Custom
Exception class, your app will have to throw it. For example, your app might
catch the SoapException, use that to create an instance of your Custom
Exception class, and then throw that. I'm not sure what exactly you're
trying to do with all this, so that' about all I can tell you.


Its hard to explain so ill try to exaplin it otherwise :)

I have an CustomSoapExcep tion wich inherit from SoapException.

To the CustomSoapExcep tion i Eg. add a property MyCustomPropert y.

Now I have extended my new SoapException compared to the baseexception.

Now i catch _some_ exeption in my webservice, eg a dberror. I create an
instanse of CustomSoapExcep tion and set the MyCustomPropert y to something
and rethrow this CustomSoapExcep tion to the client....right ?

But here is my CORE problem. How (can i?) do i access the MyCustomPropert y
on my client. Because CustomSoapExcep tion is downcastet to an ordinary
SoapException.. ...and MyCustomPropert y is gone.

AND becauase CustomSoapExcep tion is no longer an CustomSoapExcep tion on

the client i can't catch it as CustomSoapExcep tion .

Was that more clear?
Hope so anyway.
Anders

Nov 17 '05 #6
> Just a guess: The CustomSoapExcep tion is not "downcasted ", it is wrapped
in
a SoapException.
If so, catch the SoapException on the client and rethrow its innerexception (or just cast the inner
exception to CustomSoapExcep tion and access your custom property)


That was my guess too. But the InnerException is null in the
SoapException.. ....

And is try to :

catch(soapExcep tion ex)
{
string h = ((MyCustomExcep tion)ex).Messag e;
}

It tells me thats its an illigal cast........ ;(

Anders
Nov 17 '05 #7
> But here is my CORE problem. How (can i?) do i access the MyCustomPropert y
on my client. Because CustomSoapExcep tion is downcastet to an ordinary
SoapException.. ...and MyCustomPropert y is gone.
You lost me there. I don't understand how your Custom Exception can be cast
without casting it. It is what it is, unless someone casts it otherwise.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Flare" <pl*@askforit.c om> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
You can only catch the Exception that was thrown. If you create a Custom
Exception class, your app will have to throw it. For example, your app

might
catch the SoapException, use that to create an instance of your Custom
Exception class, and then throw that. I'm not sure what exactly you're
trying to do with all this, so that' about all I can tell you.


Its hard to explain so ill try to exaplin it otherwise :)

I have an CustomSoapExcep tion wich inherit from SoapException.

To the CustomSoapExcep tion i Eg. add a property MyCustomPropert y.

Now I have extended my new SoapException compared to the baseexception.

Now i catch _some_ exeption in my webservice, eg a dberror. I create an
instanse of CustomSoapExcep tion and set the MyCustomPropert y to something
and rethrow this CustomSoapExcep tion to the client....right ?

But here is my CORE problem. How (can i?) do i access the MyCustomPropert y
on my client. Because CustomSoapExcep tion is downcastet to an ordinary
SoapException.. ...and MyCustomPropert y is gone.

AND becauase CustomSoapExcep tion is no longer an CustomSoapExcep tion on

the client i can't catch it as CustomSoapExcep tion .

Was that more clear?
Hope so anyway.
Anders

Nov 17 '05 #8
> You lost me there. I don't understand how your Custom Exception can be
cast
without casting it. It is what it is, unless someone casts it otherwise.


Hehe. Before you totally give up on me. Look at your first answere.

How do I throw your MyCustomWebServ iceException and more important, how do i
catch it on the client?

My problem is taht i can't catch MyCustomWebServ iceException. My guess is,
that even though i trow my exception as MyCustomWebServ iceException its
"transforme d" into a SoapException and cant be caught by the client as
MyCustomWebServ iceException. But thats a problem because i cant access my
MyCustomPropert y anymore.

If its not clear I guess I have to give up :(

Anyway this code dosent work. ...why? (I dosent catch the exception)

The Webservice (simple)
--------------------
[WebMethod]
public void hello()
{
MyCustomWebServ iceException ce = new
MyCustomWebServ iceException(.. .fill en the parameters...);

throw(ce); // We throw this exception to the client.
}

The Client (simple)
-------------------
public void ClientTester()
{
Service1 ws = new Service1(); // Create a webserice intance via the
proxy

try
{
ws.hello();
}
catch(MyCustomW ebServiceExcept ion ex)
{
Label1.text = ex.Message;
}
}
}
Nov 17 '05 #9
My apologies. I forgot that this is a Web Service. I think the following
article from the .Net SDK will be helpful with your problem:

http://msdn.microsoft.com/library/de...ebservices.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Flare" <pl*@askforit.c om> wrote in message
news:Od******** ******@TK2MSFTN GP11.phx.gbl...
You lost me there. I don't understand how your Custom Exception can be cast
without casting it. It is what it is, unless someone casts it otherwise.


Hehe. Before you totally give up on me. Look at your first answere.

How do I throw your MyCustomWebServ iceException and more important, how do

i catch it on the client?

My problem is taht i can't catch MyCustomWebServ iceException. My guess is,
that even though i trow my exception as MyCustomWebServ iceException its
"transforme d" into a SoapException and cant be caught by the client as
MyCustomWebServ iceException. But thats a problem because i cant access my
MyCustomPropert y anymore.

If its not clear I guess I have to give up :(

Anyway this code dosent work. ...why? (I dosent catch the exception)

The Webservice (simple)
--------------------
[WebMethod]
public void hello()
{
MyCustomWebServ iceException ce = new
MyCustomWebServ iceException(.. .fill en the parameters...);

throw(ce); // We throw this exception to the client.
}

The Client (simple)
-------------------
public void ClientTester()
{
Service1 ws = new Service1(); // Create a webserice intance via the proxy

try
{
ws.hello();
}
catch(MyCustomW ebServiceExcept ion ex)
{
Label1.text = ex.Message;
}
}
}

Nov 17 '05 #10

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

Similar topics

0
3554
by: cullepm3 | last post by:
I would like to convert the xml fault information in SoapException.Detail into a class. The webservice that I am connecting defines a type called WebServiceException. All the methods provided by the webservice return this as the Fault. When I add a web reference to my C# project, VisualStudio generates a class called WebServiceException. When the web service throws an exception I would like to convert it into a WebServiceException. It...
1
1983
by: djmc | last post by:
Hi, In my web application, I catch SoapExceptions and check the SoapException.Message property to determine the error that occurred. For instance, when authenticating a user, if the incorrect password is detected, the following message is contained within SoapException.Message: Password is incorrect for user
0
1780
by: Gustavo Guerra | last post by:
If In a WebMethod I throw a SoapException("message", MyFaultCode) it's supposed to get the same exception back at the client, right? But what's really happening is that I get a SoapException always with ServerFaultCode and a full description on the message field, including stack trace, like what happens when I throw any exception not of the SoapException type. What can I be doing wrong to this to happen? Can somebody help me here? In...
16
4929
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
1
24624
by: Mike Clark | last post by:
I have a webservice that works great on localhost, but as soon as I promote to a network server I get an exception that doesn't tell me much. There's some implementation details in this exception chain, but here's what it looks like: <pre>System.Web.Services.Protocols.SoapException: Server was unable to process request. --> Object reference not set to an instance of an object. at...
3
5006
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : >************************************************************************ > <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _ > Public Function HelloWorld() As > <System.Xml.Serialization.SoapElementAttribute("return")> String
4
8521
by: asanford | last post by:
http://msdn2.microsoft.com/en-us/library/ds492xtk.aspx Is this the following excerpt from the above page incorrect, or is there a bug in the .net 2.0 implementation? Or perhaps I have something configured wrong. Basically, the doc says that when a custom exception type is thrown from a web method, that the web service client app will receive a soapexception with the soapexception.InnerException property set to reference the custom...
0
1488
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 communication (that's not so correct, I hope you understand what I mean). Here is my class:
0
1922
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 communication (that's not so correct, I hope you understand what I mean). Here is my class:
0
9485
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10098
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9958
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6743
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.