473,626 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code design ideas?

Hello all,

I need some design advice for my web service.

I' have written a web service that exposes a function that takes some
parameters

and return an xml.

The function have up to 10 parameters. There are many situations where the
function returns an error xml.

The parameters need to be checked in many differents ways (10 power X ways).
So an error xml is just returned to the caller.

I'm looking for a pattern to best implement this. So far, i have written a
working code but , i'm not really proud of writing this code.

I beleive /i'm convinced it can be done much better. The code does works as
it should. The only problem is the design.

I'm looking at some pattern (maybe GOF) or other patterns that can be used.

Any idea?

Thanks

JJ
Nov 22 '06 #1
9 1691
adi
JJ

I implemented the following pattern in my webservice. Below is a
simplified view.
When calling a webmethod, I see two types of errors:
1. Subsystem errors. Like: there is no connectivity between the client
app and the webservice, etc. These are errors that are independent from
my code inside the webservice

2. System errors. These errors are the direct or indirect effect of my
code inside the webservice. Like: executing a select statement while
the database is down, or raising an error from inside my own code, etc,
etc.

Now, my design pattern says:

A. Errors of type 1 should be handled by the client side. For example,
you should identify the error and display "There is no conectivity with
the server", etc.

B. Errors of type 2 should ALWAYS be handled by my code. Then the
caught exception will be sent to a method that will identify it and
will assign a unique error code along with some text that will describe
the error. Usually it is the Message of the Exception.
Unidentified exception should have also an error code. I also assign a
severity level for each identified exception; for now, I have only 2
severity levels: warning and error.
So, when an exception of type 2 occurs, I create an XML string
containing:
- the error code obtained after the exception is identified
- the error text. Each exception caught has a Message
- the severity level; my case: warning or error

Now, the information about the error is ready. We only have to
transport it to the client.
I chose to transport it using an SoapException object. How? I fill the
Detail member with the information about the error and throw the
SoapException object.
The client will listen for exceptions of SoapException type and will
analyse them.
If the object caught has its Detail member null, then we know that the
exception is of type 1 and try to identify the exception on the client
side. If Detail property is not null, you just have to interpret the
data contained inside and provide to the user the apropriate feedback.

Now, in my real application, I have to deal with errors and warnings
inside my webservice. Errors are simple: when you encounter one just
rollback some operations if needed and exit. Anyway, warnings bring a
bit of complexity here. I mean, you need to warn the user about
something, but this doesn't mean you have to exit. Au contraire, you
need to continue processing and at the end TO RETURN THE RESULT OF
PROCESSING.

I solved this issue by defining a Response object that contains 2 main
parts:
1. A header containing error and/or warning messages. Why multiple?
Because when processing, you could yield multiple warning messages in a
single request.
2. A data section that contains the results of the processing.

My methods always return an xml string that describe such an Response
object that will be recreated on the client side.

Jens Jensen a scris:
Hello all,

I need some design advice for my web service.

I' have written a web service that exposes a function that takes some
parameters

and return an xml.

The function have up to 10 parameters. There are many situations where the
function returns an error xml.

The parameters need to be checked in many differents ways (10 power X ways).
So an error xml is just returned to the caller.

I'm looking for a pattern to best implement this. So far, i have written a
working code but , i'm not really proud of writing this code.

I beleive /i'm convinced it can be done much better. The code does works as
it should. The only problem is the design.

I'm looking at some pattern (maybe GOF) or other patterns that can be used.

Any idea?

Thanks

JJ
Nov 22 '06 #2
I implemented the following pattern in my webservice. Below is a
simplified view.
When calling a webmethod, I see two types of errors:
1. Subsystem errors. Like: there is no connectivity between the client
app and the webservice, etc. These are errors that are independent from
my code inside the webservice

2. System errors. These errors are the direct or indirect effect of my
code inside the webservice. Like: executing a select statement while
the database is down, or raising an error from inside my own code, etc,
etc.

Now, my design pattern says:

A. Errors of type 1 should be handled by the client side. For example,
you should identify the error and display "There is no conectivity with
the server", etc.

B. Errors of type 2 should ALWAYS be handled by my code. Then the
caught exception will be sent to a method that will identify it and
will assign a unique error code along with some text that will describe
the error. Usually it is the Message of the Exception.
Unidentified exception should have also an error code. I also assign a
severity level for each identified exception; for now, I have only 2
severity levels: warning and error.
So, when an exception of type 2 occurs, I create an XML string
containing:
- the error code obtained after the exception is identified
- the error text. Each exception caught has a Message
- the severity level; my case: warning or error

Now, the information about the error is ready. We only have to
transport it to the client.
I chose to transport it using an SoapException object. How? I fill the
Detail member with the information about the error and throw the
SoapException object.
The client will listen for exceptions of SoapException type and will
analyse them.
If the object caught has its Detail member null, then we know that the
exception is of type 1 and try to identify the exception on the client
side. If Detail property is not null, you just have to interpret the
data contained inside and provide to the user the apropriate feedback.

Now, in my real application, I have to deal with errors and warnings
inside my webservice. Errors are simple: when you encounter one just
rollback some operations if needed and exit. Anyway, warnings bring a
bit of complexity here. I mean, you need to warn the user about
something, but this doesn't mean you have to exit. Au contraire, you
need to continue processing and at the end TO RETURN THE RESULT OF
PROCESSING.

I solved this issue by defining a Response object that contains 2 main
parts:
1. A header containing error and/or warning messages. Why multiple?
Because when processing, you could yield multiple warning messages in a
single request.
2. A data section that contains the results of the processing.

My methods always return an xml string that describe such an Response
object that will be recreated on the client side.

Hi Adi,
Is this a standard pattern or an home made one? I strive to use standard
method. But i do understand they might not always apply in particular cases.
If what you describe is in fact a standard pattern then, where can i read
more about it?
Many thanks
JJ
Nov 22 '06 #3
adi
Sorry, this is my "hand-made" pattern.
No standard pattern I read about satisfied all my needings.
If you find one, I kindly ask you to post it here.

Thanks.
Adi.
Jens Jensen a scris:
I implemented the following pattern in my webservice. Below is a
simplified view.
When calling a webmethod, I see two types of errors:
1. Subsystem errors. Like: there is no connectivity between the client
app and the webservice, etc. These are errors that are independent from
my code inside the webservice

2. System errors. These errors are the direct or indirect effect of my
code inside the webservice. Like: executing a select statement while
the database is down, or raising an error from inside my own code, etc,
etc.

Now, my design pattern says:

A. Errors of type 1 should be handled by the client side. For example,
you should identify the error and display "There is no conectivity with
the server", etc.

B. Errors of type 2 should ALWAYS be handled by my code. Then the
caught exception will be sent to a method that will identify it and
will assign a unique error code along with some text that will describe
the error. Usually it is the Message of the Exception.
Unidentified exception should have also an error code. I also assign a
severity level for each identified exception; for now, I have only 2
severity levels: warning and error.
So, when an exception of type 2 occurs, I create an XML string
containing:
- the error code obtained after the exception is identified
- the error text. Each exception caught has a Message
- the severity level; my case: warning or error

Now, the information about the error is ready. We only have to
transport it to the client.
I chose to transport it using an SoapException object. How? I fill the
Detail member with the information about the error and throw the
SoapException object.
The client will listen for exceptions of SoapException type and will
analyse them.
If the object caught has its Detail member null, then we know that the
exception is of type 1 and try to identify the exception on the client
side. If Detail property is not null, you just have to interpret the
data contained inside and provide to the user the apropriate feedback.

Now, in my real application, I have to deal with errors and warnings
inside my webservice. Errors are simple: when you encounter one just
rollback some operations if needed and exit. Anyway, warnings bring a
bit of complexity here. I mean, you need to warn the user about
something, but this doesn't mean you have to exit. Au contraire, you
need to continue processing and at the end TO RETURN THE RESULT OF
PROCESSING.

I solved this issue by defining a Response object that contains 2 main
parts:
1. A header containing error and/or warning messages. Why multiple?
Because when processing, you could yield multiple warning messages in a
single request.
2. A data section that contains the results of the processing.

My methods always return an xml string that describe such an Response
object that will be recreated on the client side.


Hi Adi,
Is this a standard pattern or an home made one? I strive to use standard
method. But i do understand they might not always apply in particular cases.
If what you describe is in fact a standard pattern then, where can i read
more about it?
Many thanks
JJ
Nov 22 '06 #4
Hi Adi,
I found the belwo:
http://msdn2.microsoft.com/en-us/library/aa480534.aspx

Maybe you also might want to have a look.
Thanks
JJ
Nov 22 '06 #5

I would personally shy away from any web-service that directly returns
XML or forces the caller to directly handle XML. The power of web
services is in the automatic serialization and deserialization of
native objects to XML. As soon as you return XML from a web service
then you're forcing the caller to work with XML directly when the web
service library in their language would most likely have abstracted
this away for them.

The same is true for errors, Web Services have a standard way to deal
with errors and you can take advantage of this simply by throwing
errors in your web service method, which will be serialized to XML
according to SOAP standards and most client libraries will handle it
accordingly.

So I would say don't return XML and don't handle errors differently.
Certainly you want to trap internal errors and translate them to
something the caller will understand and can work with, but don't
return something that purports to be an OK resopnse (i.e., not a
standard SOAP error) which is really a custom error format.

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.


On Wed, 22 Nov 2006 12:53:22 +0100, "Jens Jensen" <jj@jensen.dk >
wrote:
>Hello all,

I need some design advice for my web service.

I' have written a web service that exposes a function that takes some
parameters

and return an xml.

The function have up to 10 parameters. There are many situations where the
function returns an error xml.

The parameters need to be checked in many differents ways (10 power X ways).
So an error xml is just returned to the caller.

I'm looking for a pattern to best implement this. So far, i have written a
working code but , i'm not really proud of writing this code.

I beleive /i'm convinced it can be done much better. The code does works as
it should. The only problem is the design.

I'm looking at some pattern (maybe GOF) or other patterns that can be used.

Any idea?

Thanks

JJ
Nov 22 '06 #6

"Samuel R. Neff" <sa********@nom ail.comskrev i en meddelelse
news:es******** *************** *********@4ax.c om...
>
I would personally shy away from any web-service that directly returns
XML or forces the caller to directly handle XML. The power of web
services is in the automatic serialization and deserialization of
native objects to XML. As soon as you return XML from a web service
then you're forcing the caller to work with XML directly when the web
service library in their language would most likely have abstracted
this away for them.

The same is true for errors, Web Services have a standard way to deal
with errors and you can take advantage of this simply by throwing
errors in your web service method, which will be serialized to XML
according to SOAP standards and most client libraries will handle it
accordingly.

So I would say don't return XML and don't handle errors differently.
Certainly you want to trap internal errors and translate them to
something the caller will understand and can work with, but don't
return something that purports to be an OK resopnse (i.e., not a
standard SOAP error) which is really a custom error format.

HTH,

Sam


Hi Sam,
Thank you for your very interesting input to this discussion and i do
understand your point.
Can you provide link to some online resources on this subject?

I used this method after consuming an oracle application web service.
I know wonder why they have adopted this strategy?

Thanks
JJ
Nov 22 '06 #7

Here's a good starting point on MSDN. The links include a design
guideline page (which is unfortunately brief) and discussion of error
handling:

http://msdn2.microsoft.com/en-gb/library/ba0z6a33.aspx

Also as a learning experience I would highly recommend writing a few
web services in several languages (particularly .NET and Java) and
then writing client code to consume each from every language. Be sure
to include services that both accept and return complex content. That
experience of programming cross-language web services will give you a
better understanding of developing client-friendly web services.

Best regards,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

>Hi Sam,
Thank you for your very interesting input to this discussion and i do
understand your point.
Can you provide link to some online resources on this subject?

I used this method after consuming an oracle application web service.
I know wonder why they have adopted this strategy?

Thanks
JJ
Nov 22 '06 #8
Hello ! JJ jj@jensen.dk , :-)) ,
Are you the same professional that went to Brazil - DK - for F.L.Smidth
S/A,
to work for the project - cement industry MAUA-CANTAGALO ?

If so... - Do you still works for F. L. Smidth DK ????

Jens Jensen escreveu:
Hello all,

I need some design advice for my web service.

I' have written a web service that exposes a function that takes some
parameters

and return an xml.

The function have up to 10 parameters. There are many situations where the
function returns an error xml.

The parameters need to be checked in many differents ways (10 power X ways).
So an error xml is just returned to the caller.

I'm looking for a pattern to best implement this. So far, i have written a
working code but , i'm not really proud of writing this code.

I beleive /i'm convinced it can be done much better. The code does works as
it should. The only problem is the design.

I'm looking at some pattern (maybe GOF) or other patterns that can be used.

Any idea?

Thanks

JJ
Nov 26 '06 #9
MB**********@gm ail.com wrote:
Hello ! JJ jj@jensen.dk , :-)) ,
Are you the same professional that went to Brazil - DK - for F.L.Smidth
S/A,
to work for the project - cement industry MAUA-CANTAGALO ?
It could be your old friend, but note that Jens Jensen is not an unusual
name in Denmark.

[the danish statistical agency claims that there are 4579
of them]

Arne
Nov 26 '06 #10

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

Similar topics

36
6361
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but something I'll need in this case is some experience-based set of rules about how to use python in this context. For example... is defining readonly attributes in classes worth the hassle ? Does duck-typing scale well in complex
242
13323
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
2
3566
by: Kymert persson | last post by:
Hi. I was wondering if there are any more C++ books along the lines of "Large scale C++ software design" by Lakos, J. I.e. concerning larger design issues in close relation to C++. I have made a fairly thorough literature search, but i haven't found anything fitting this criteria. In general there seems to be a huge amount concerning the C++ language as such and more "narrow" design issues, e.g. along the lines of Meyers Effective-
3
1225
by: SpamProof | last post by:
I'm looking for an example of a detailed design that I can follow or get ideas from before programming in vb.net. Currently, I'm using this outline approach that describes my Project, Classes, Methods, properties etc and it goes something like this... I. Project: ProjectName A. Class: ClassName 1. New Method: MethodName a. Method Description: Explain method purpose
6
2164
by: Mario T. Lanza | last post by:
Greetings, I don't know about you guys but on many occasions I've asked myself whether or not someone else has solved a particular programming issue -- whether or not they developed a clever pattern for doing some task quite well. This usually leads me to a search on today's greatest technical tool, The Internet. I indefinitely uncover many potential code snippets, components, etc. and have to weed through them to find the best one...
12
3289
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. Such things happen. The whole subsystem is going through radical changes. I don't really want to say what I think of the code just yet. That would influence the opinions of others, and I really want to know how other people view these things,...
67
4242
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. Unfortunately these ad hominem rhetorts are frequently introduced into purely technical discussions on the feasibility of supporting such functionality in C++. That usually serves to divert the discussion from the technical subject to a discussion of the...
171
7688
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
22
4710
by: Krivenok Dmitry | last post by:
Hello All! I am trying to implement my own Design Patterns Library. I have read the following documentation about Observer Pattern: 1) Design Patterns by GoF Classic description of Observer. Also describes implementation via ChangeManager (Mediator + Singleton) 2) Pattern hatching by John Vlissides Describes Observer's implementation via Visitor Design Pattern. 3) Design Patterns Explained by Alan Shalloway and James Trott
16
2791
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
0
8192
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
8696
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...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8358
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
7188
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5571
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
4090
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...
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1504
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.