Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I declare my Web Method so the Soap Response display more elements than just a single element ?

Posted on 2011-10-15
4
Medium Priority
?
362 Views
Last Modified: 2012-05-12

If I create my WebMethod like this...
<WebMethod()> _
    Public Function Test(ByVal FirstName As String _
            , ByVal LastName As String _
            , ByVal City As String _
            ) As String

The Soap Request listing on my test.asmx file looks like this...
  <soap:Body>
    <Test xmlns="http://test.com/">
      <Firstname>string</Firstname>
      <LastName >string</LastName >
      <City>string</City>
    </Test>
  </soap:Body>

and my Soap Response looks like....
  <soap:Body>
    <TestResponse xmlns="http://test.com/">
      <TestResult>string</TestResult>
    </TestResponse>
  </soap:Body>

QUESTION:
How do I declare my Web Method so the Soap Response looks like this...
  <soap:Body>
    <TestResponse xmlns="http://test.com/">
      <TestResult>
      <Color>string</Color>
      <Age>string</Age>
      <Speed>string</Speed>
     </TestResult>
    </TestResponse>
  </soap:Body>



0
Comment
Question by:MikeCombe
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:ErezMor
ID: 36975553
since a function can only return a single value (or object), your return structure is not possible.
maybe return a delimited string with all desired values, then break it down to it's components on the end application:
say the function return a single string like "Red|24|100"
and the end application uses split function with "|" delimiter
0
 

Author Comment

by:MikeCombe
ID: 36975902
Got it. I didn't realize that the webservice was just a function, so that makes sense. Would it be propert to return the "string" as this...
<Color>string</Color><Age>string</Age><Speed>string</Speed>
.... could that be parsed by normal xml ?

or....is it better to "return" an xml document ?
0
 
LVL 12

Accepted Solution

by:
ErezMor earned 2000 total points
ID: 36977120
since xml is nothing more than (meaningful) plain text, you can return your suggestion as string AND parse it on the other end as xml, BUT, if all you need is very few data values, like the example you gave, AND you are the client on the "other end of the line" (that is you are the only one consuming the web service from a .net application), then i'd suggest again the delimited string, it's much faster both to build on the web service side and to break-down on the end application

remember that the xml you "see" when browsing the asmx file (like the one you added to your question), is behind the scenes when you consume the service, where it works like any other function, as if it was a local dll or function in your app.

hope i am clear enough, ask if not
0
 

Author Closing Comment

by:MikeCombe
ID: 36977207
Thanks...I wasn't sure if I needed to have my web service return an xml string or an xml document. I will return an xml string. My example was brief just to understand the concept. My actual response will be a string (in xml format) with about 20-30 element tags. I am planning on using the standard   <?xml version="1.0" encoding="utf-8" ?> ...is that correct? Here's my sample response within the soap container:      

<soap:Body>
    <TestResponse xmlns="http://test.com/">
      <TestResult>
                    <?xml version="1.0" encoding="utf-8" ?>
                    <myResult>
                     <Color>string</Color>
                     <Age>string</Age>
                     <Speed>string</Speed>
                     </myResult>
     </TestResult>
    </TestResponse>
  </soap:Body>
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question