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

How .NET web services client handles exceptions from Java web services?

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> element.

However, when I try to do the same thing using wsdl.exe or add web
references in Visual Studio .NET, looks like it doesn't generate any
custom exception classes
that correspond to <wsdl:fault> element in WSDL file.

My question is how .NET web services client handles exceptions from
Java web services? How .NET web services client handle the SOAP
exception response?
Please advise. thanks!!

Mar 9 '06 #1
4 3005
Hi,

Provided that you are using SOAP to access the web service, a SoapException
will be thrown on the client. I believe (yet I may not be entirely correct)
that WCF (aka Indigo) will generate custom classes for fault elements and
now comes with the GoLive license so this might be the way go if you really
need what you have described. If not then you could just provide a generic
SoapException handling mechanism on the client.

Best regards,
Robert Wilczynski

wi***************@gmail.com

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> element.

However, when I try to do the same thing using wsdl.exe or add web
references in Visual Studio .NET, looks like it doesn't generate any
custom exception classes
that correspond to <wsdl:fault> element in WSDL file.
My question is how .NET web services client handles exceptions from
Java web services? How .NET web services client handle the SOAP
exception response?

Please advise. thanks!!

Mar 9 '06 #2

Robert Wilczynski wrote:
Hi,

Provided that you are using SOAP to access the web service, a SoapException
will be thrown on the client. I believe (yet I may not be entirely correct)
that WCF (aka Indigo) will generate custom classes for fault elements and
now comes with the GoLive license so this might be the way go if you really
need what you have described. If not then you could just provide a generic
SoapException handling mechanism on the client.

Best regards,
Robert Wilczynski


Rob:

I am using Visual Studio .NET 2003 Enterprise Architect, and when I run
wsdl.exe or add web reference, the auto-generated code doesn't generate
any custom exception classes that correspond to <wsdl:fault> element in
WSDL file. Based on what you said, it seems normal, and we need to
create those custom exception classes manually if we want the custom
exception class. Correct?

I tried to download Indigo from
http://msdn.microsoft.com/webservices/indigo/, but it always say the
download site is unavailable now.

Mar 9 '06 #3
> [...] Based on what you said, it seems normal, and we
need to create those custom exception classes manually if we want the
custom exception class. Correct?
Yes you are correct, but there still remains the problem of actually catching
the SoapException and rethrowing it as something more meaningful.

When the response is received from the webservice, the SoapHttpClientProtocol
class (a base class for proxies) parses the message and when it finds the
fault element it turns it into a SoapException and initializes the instance
with the values from the fault element (fault code and subcode, details node
etc). If you look into the autogenerated Visual Studio proxy you will notice
that each WS operation is called using the following code:

object[] results = this.Invoke("OperationName", new object[] {operationNameRequestObject});

You could of course mess with the proxy, surround all those calls with try..catch
block and provide your own logic to turn the SoapException into a custom
one. This is of course a really bad approach as

1) you would have to repeat this whenever the proxy is regenerated
2) depending on the amount of operations exposed by the service this could
be many lines of custom code to write

Instead what I would do would be to create your own base proxy class MyHttpClientProtocol
deriving from SoapHttpClientProtocol and override the Invoke method:

protected override object[] Invoke(string methodName, object[] parameters)
{
try
{
base.Invoke(methodName, parameters);
} catch (SoapException ex)
{
throw GetCustomException(ex);
}
}

where GetCustomException would provide an instance of your own exception
based on the fault code and subcode. I believe you could point wsdl.exe to
this use this class as a base class for the proxy it generates. This probably
is, at least conceptually, the easiest approach.

A better approach however would be to leverage the extensibility of the framework
and to use the soap extensions mechanism (http://msdn.microsoft.com/library/de...lasstopic.asp).
Such extension would probably parse the response message to see if it was
a fault and deserialize it into an instanse of your custom exception.

You should of course make the decision based on on your needs and the time
you have to implement the client application. I hope this will help you to
make up your mind.

Best regards,
Robert Wilczynski

wi***************@gmail.com
Robert Wilczynski wrote:
Hi,

Provided that you are using SOAP to access the web service, a
SoapException will be thrown on the client. I believe (yet I may not
be entirely correct) that WCF (aka Indigo) will generate custom
classes for fault elements and now comes with the GoLive license so
this might be the way go if you really need what you have described.
If not then you could just provide a generic SoapException handling
mechanism on the client.

Best regards,
Robert Wilczynski

Rob:

I am using Visual Studio .NET 2003 Enterprise Architect, and when I
run wsdl.exe or add web reference, the auto-generated code doesn't
generate any custom exception classes that correspond to <wsdl:fault>
element in WSDL file. Based on what you said, it seems normal, and we
need to create those custom exception classes manually if we want the
custom exception class. Correct?

I tried to download Indigo from
http://msdn.microsoft.com/webservices/indigo/, but it always say the
download site is unavailable now.

Mar 10 '06 #4

Robert Wilczynski wrote:
Instead what I would do would be to create your own base proxy class MyHttpClientProtocol
deriving from SoapHttpClientProtocol and override the Invoke method:

protected override object[] Invoke(string methodName, object[] parameters)
{
try
{
base.Invoke(methodName, parameters);
} catch (SoapException ex)
{
throw GetCustomException(ex);
}
}

where GetCustomException would provide an instance of your own exception
based on the fault code and subcode. I believe you could point wsdl.exe to
this use this class as a base class for the proxy it generates. This probably
is, at least conceptually, the easiest approach.


Rob:

Thanks a lot for your advices. But I still have problem on this easiest
approach.

I created a custom exception class MyWizardException, and created my
own
base proxy class MyHttpClientProtocol derived from
SoapHttpClientProtocol and
override the Invoke method. But I got the following error:

'MyDOC1.MyWebReference.MyHttpClientProtocol.Invoke (string, object[])' :
cannot override inherited member
'System.Web.Services.Protocols.SoapHttpClientProto col.Invoke(string,
object[])' because it is not marked virtual, abstract, or override

Here's the SOAP response:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode
xmlns:ns201420873="http://mywizard.wws"
xmlns="">ns201420873:MyWizardException</faultcode><faultstring
xmlns=""><![CDATA[wws.mywizard.MyWizardException: sequence number need
to be >0]]></faultstring><detail xmlns=""><MyWizardGException
xmlns="http://mywizard.wws"><info>info001</info><message>sequence
number need to be
&gt;0</message><id>1</id></MyWizardGException></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>

My objective is to extract the <info>, <message>, and <id> elements.
And then map those values to the custom exception class
MyWizardException

In visual studio autogenerated proxy file, I added and modified the
following:

public class MyWizardException : System.ApplicationException
{
public string info;
public string message;
public int id;

public MyWizardException(string aInfo, string aMessage, int aId)
{
info = aInfo;
message = aMessage;
id = aId;
}

}
public class MyHttpClientProtocol :
System.Web.Services.Protocols.SoapHttpClientProtoc ol
{
protected override object[] Invoke(string methodname, object[]
parameters)
{
try
{
base.Invoke(methodname, parameters);
}
catch(System.Web.Services.Protocols.SoapException ex)
{ throw MyWizardException(ex);
}
}

}

public class MyWebService :
System.Web.Services.Protocols.SoapHttpClientProtoc ol
{
//etc...
}
any ideas what I am missing here?

Please advise. thanks!!

Mar 31 '06 #5

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

Similar topics

2
by: Liza | last post by:
I've learnt that there are 3 types of web services...........one that provide information, once that provide a transaction, ones are an integration of webservices. WHy bother have a web service...
1
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...
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); }
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 : ...
18
by: Larry Herbinaux | last post by:
I'm having issues with garbage collection with my long-standing service process. If you could review and point me in the right direction it would be of great help. If there are any helpful...
0
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>...
1
by: yancheng.cheok | last post by:
Hi all, According to "How can I handle a constructor that fails?" in http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.2, whenever there is a constructor fail, we will throw...
6
by: Simon Harvey | last post by:
Hi everyone, We have a need to make a Windows Forms (2.0) client application that will be installed on our clients site. The data that the application uses needs to be centrally available to a...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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.