Can a web service return our own predefined xml format

a1jit

Well-known member
Joined
Aug 19, 2005
Messages
89
Hi Guys,

I have been finding for this answer for quite some time but fail.
My question is that can we control that xml output from a web service?

Let me explain

I have a small method like this in my web service

Code:
      public decimal AddNumbers(decimal lnNumber1, decimal lnNumber2)   {

            return lnNumber1 + lnNumber2; 

      }

After data is keyed in, i automatically get this format.

Code:
<?xml version="1.0" ?> 

<decimal xmlns="http://tempuri.org/">32.12</decimal>

So here, can i change the xml format in a web service?

Maybe i want this format

Code:
<?xml version="1.0" ?> 

<number1> 2 </number1>
<number2> 3 </number2>
<results> 5 </results>

This is just a sample, i want to do something like this, but it seems web service doesnt allow me to do this.

I hope someone can provide me with some useful links,suggesstions or codes on how to do this..

thank you very very much for any help
 
The easiest way would be to define a class that exposes the 3 fields you want returned and return a valid instance of this from the WebMethod.
 
Back
Top