473,387 Members | 1,516 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,387 software developers and data experts.

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

MyCustomWebServiceException : 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 3150
Example:
MyCustomWebServiceException : soapException
{
private string _MyCustomProperty;
public string MyCustomProperty
{
get
{
return _MyCustomProperty;
}
}
public MyCustomWebServiceException(string message,
XmlQualifiedName code, string CustomParameter)
: base(string message, XmlQualifiedName code)
{
_MyCustomProperty = 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.com> wrote in message
news:OK*************@TK2MSFTNGP11.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

MyCustomWebServiceException : 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 MyCustomWebServiceException i have problems. I cant catch
my exception as MyCustomWebServiceException, 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.ClassLibraries.TurabsException.Turabs WebServiceException:
Calculation error---> System.DivideByZeroException: Calculation error. at
WebServiceExp.Service1.HelloWorld() in
c:\inetpub\wwwroot\webserviceexp\service1.asmx.cs: line 58 --- Slut på
staksporing af indre undtagelser --- at WebServiceExp.Service1.HelloWorld()
in c:\inetpub\wwwroot\webserviceexp\service1.asmx.cs: line 66
------>

My Message "Calculation 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.DivideByZeroException DivideExp)
{
TurabsWebServiceException TurDBExp = new
TurabsWebServiceException("Calculation
error",System.Web.Services.Protocols.SoapException .ServerFaultCode,DivideExp
);

throw(TurDBExp); //Rethrow to client
}

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

try
{
a.HelloWorld();
}
catch(System.Web.Services.Protocols.SoapException 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.com> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
Thx :)

But. When i trow MyCustomWebServiceException i have problems. I cant catch
my exception as MyCustomWebServiceException, 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.ClassLibraries.TurabsException.Turabs WebServiceException:
Calculation error---> System.DivideByZeroException: Calculation error. at
WebServiceExp.Service1.HelloWorld() in
c:\inetpub\wwwroot\webserviceexp\service1.asmx.cs: line 58 --- Slut på
staksporing af indre undtagelser --- at WebServiceExp.Service1.HelloWorld() in c:\inetpub\wwwroot\webserviceexp\service1.asmx.cs: line 66
------>

My Message "Calculation 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.DivideByZeroException DivideExp)
{
TurabsWebServiceException TurDBExp = new
TurabsWebServiceException("Calculation
error",System.Web.Services.Protocols.SoapException .ServerFaultCode,DivideExp );

throw(TurDBExp); //Rethrow to client
}

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

try
{
a.HelloWorld();
}
catch(System.Web.Services.Protocols.SoapException 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 CustomSoapException wich inherit from SoapException.

To the CustomSoapException i Eg. add a property MyCustomProperty.

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 CustomSoapException and set the MyCustomProperty to something
and rethrow this CustomSoapException to the client....right?

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

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

Was that more clear?
Hope so anyway.
Anders

Nov 17 '05 #5
SF
Just a guess: The CustomSoapException 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 CustomSoapException and access your custom property)

"Flare" <pl*@askforit.com> wrote in message
news:#4*************@TK2MSFTNGP10.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 CustomSoapException wich inherit from SoapException.

To the CustomSoapException i Eg. add a property MyCustomProperty.

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 CustomSoapException and set the MyCustomProperty to something
and rethrow this CustomSoapException to the client....right?

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

AND becauase CustomSoapException is no longer an CustomSoapException on

the client i can't catch it as CustomSoapException .

Was that more clear?
Hope so anyway.
Anders

Nov 17 '05 #6
> Just a guess: The CustomSoapException 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 CustomSoapException and access your custom property)


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

And is try to :

catch(soapException ex)
{
string h = ((MyCustomException)ex).Message;
}

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 MyCustomProperty
on my client. Because CustomSoapException is downcastet to an ordinary
SoapException.....and MyCustomProperty 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.com> wrote in message
news:%2***************@TK2MSFTNGP10.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 CustomSoapException wich inherit from SoapException.

To the CustomSoapException i Eg. add a property MyCustomProperty.

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 CustomSoapException and set the MyCustomProperty to something
and rethrow this CustomSoapException to the client....right?

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

AND becauase CustomSoapException is no longer an CustomSoapException on

the client i can't catch it as CustomSoapException .

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 MyCustomWebServiceException and more important, how do i
catch it on the client?

My problem is taht i can't catch MyCustomWebServiceException. My guess is,
that even though i trow my exception as MyCustomWebServiceException its
"transformed" into a SoapException and cant be caught by the client as
MyCustomWebServiceException. But thats a problem because i cant access my
MyCustomProperty 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()
{
MyCustomWebServiceException ce = new
MyCustomWebServiceException(...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(MyCustomWebServiceException 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.com> wrote in message
news:Od**************@TK2MSFTNGP11.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 MyCustomWebServiceException and more important, how do

i catch it on the client?

My problem is taht i can't catch MyCustomWebServiceException. My guess is,
that even though i trow my exception as MyCustomWebServiceException its
"transformed" into a SoapException and cant be caught by the client as
MyCustomWebServiceException. But thats a problem because i cant access my
MyCustomProperty 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()
{
MyCustomWebServiceException ce = new
MyCustomWebServiceException(...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(MyCustomWebServiceException 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
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...
1
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...
0
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...
16
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...
1
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...
3
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 : ...
4
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...
0
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...
0
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.