2

There is a php application which will read the result from the web service i have created. The xml response they want is like

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Header />
 <s:Body>
 <WorkResponse xmlns="http://tempuri.org/">
 <WorkResult>Name<WorkResult>
 <WorkResult>Occupation<WorkResult>
 </WorkResult>
 </WorkResponse>
 </s:Body>

But my method return like this `

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Header />
 <s:Body>
 <WorkResponse xmlns="http://tempuri.org/">
 <WorkResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
 <a:string>Name</a:string>
 <a:string>Occupation</a:string>
 </WorkResult>
 </WorkResponse>
 </s:Body>`

And below is the method I have written in the web service

public string[] Work()
 {
 string[] request = new String[2];
 request[0] = "Name";
 request[1] = "Occupation";
 return request;
 }

How can I do to get the result they want. Please help me to come out of this issue

asked Aug 28, 2017 at 14:29
2
  • Did you try my answer? Commented Aug 28, 2017 at 15:02
  • I am doing it in wcf service Commented Aug 29, 2017 at 5:36

1 Answer 1

1

If you need WorkResult node to contain both "Name" and "Occupation" and at the same level in the xml, you can achieve it returning a List in your WebMethod Work(). Here is an example:

public List<String> Work()
{
 public List<String> result = new List<String>();
 result.Add("Name");
 result.Add("Occupation");
 return result;
}
answered Aug 28, 2017 at 14:45
4
  • Can you add an explanation of your code and why it solves the issue? Code only answers are often not that helpful. Commented Aug 28, 2017 at 17:31
  • Thank's @Zabuza for the suggestion. Commented Aug 28, 2017 at 17:39
  • I tried with it. But the result is same italic bold <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header /> <s:Body> <WorkResponse xmlns="http://tempuri.org/"> <WorkResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <a:string>Name</a:string> <a:string>Occupation</a:string> </WorkResult> </WorkResponse> </s:Body> Commented Aug 29, 2017 at 2:55
  • I am doing it in wcf service Commented Aug 29, 2017 at 5:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.