?
Solved

can a web method in a web service accept an xml string and return an xml string?

Posted on 2009-04-11
3
Medium Priority
?
706 Views
Last Modified: 2012-08-13
Hi,
Can somebody please clarify how to parse an xml string in a web method and also return xml in the form of a string? I am not sure if I framed the question meaningfully? My web method's signature is as follows.
public string CreateAccount(string XMLInfo)
In the above method, XMLInfo is a string consisting of xml and I should be able to parse the xml in the web method. And also I would return multiple values but through a single string consisting of again xml. It would be a great help if you could post me a code sample in C#.
Thanks for any help!
0
Comment
Question by:ipjyo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Expert Comment

by:Nirmalan Nagenthiran
ID: 24124523
Yes its possible. Pass that XML file as a string and inside the web method convert it back to XML, do all XML processing.
Here is the code piece.

 [WebMethod]
 public string ProcessXML(string xmlInfo)
 {
     XmlDocument document = new XmlDocument();
     document.LoadXml(xmlInfo);
 
     // Add more values to the XML file.
         
     // Return XML as String.
     return document.InnerXml;
 }

Open in new window

0
 

Author Comment

by:ipjyo
ID: 24124544
Thanks for the response.
could you also clarify how would the consumer of this web method know what input parameters that should be given?
If we pass 5 individual parameters then the consumer will have 5 text boxes to enter data. but how will this happen if we pass xml as a string? what will the consumer see when he tries to access the web service? Thank you!
0
 
LVL 12

Accepted Solution

by:
Nirmalan Nagenthiran earned 1500 total points
ID: 24124627
Please find the attach code pieces. Let me know your thoughts.
<!-- UserInput.xml -->
 
<?xml version="1.0" encoding="UTF-8"?>
<USERINPUT>
    <TITLE>Add your Title Here</TITLE>
    <FIRSTNAME>Add your Firstname</FIRSTNAME> 
    <LASTNAME>Add your Lastname</LASTNAME>
    <ADDRESS>Add your address</ADDRESS>
    <TELEPHONE>Add your telephone</TELEPHONE>
</USERINPUT>   
 
// Web Service - Web Method
 
[WebMethod]
public string CreateAccount(string xmlinfo)
{
    // Load XML.
    XmlDocument document = new XmlDocument();
    document.LoadXml(xmlinfo);
 
    // Add/Modify values to the XML file.
            
    // Return XML as String.
    return document.InnerXml;
}
 
// Consume WebService
 
protected void Page_Load(object sender, EventArgs e)
{
     // Load the UserInput.Xml
     XmlDocument doc = new XmlDocument();
     doc.Load(@"C:\UserInput.xml");
 
     // Add 5 input values into the XML file
 
     // Call the Webservice and pass the XML.
     Service1 service = new Service1();
     string responseXML =  service.CreateAccount(doc.InnerText);
 
     // Again load the response as XML.
     doc.LoadXml(responseXML);
 
     // Do other manipulations here..
}

Open in new window

0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

765 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