Link to home
Start Free TrialLog in
Avatar of MikeCombe
MikeCombeFlag for United States of America

asked on

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


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>



Avatar of ErezMor
ErezMor
Flag of Australia image

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
Avatar of MikeCombe

ASKER

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 ?
ASKER CERTIFIED SOLUTION
Avatar of ErezMor
ErezMor
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>