title: Read XML response webservice
body: <p>I am so new to .Net web service programming.  I am running into a trouble to read the XML response from web services to my client. </p>
  
  <p>In my webservice side: Service1.asmx.cs code: </p>
  
  <pre><code>    [WebMethod(Description = "substruction")]
      public double subtract(double i, double j)
      {
          return i - j;
      }
  
  
      [WebMethod(Description = "getxml")]
      public XmlDocument GetXML()
      {
          StringBuilder sb = new StringBuilder();
          XmlWriter writer = XmlWriter.Create(sb);
  
          writer.WriteStartDocument();
          writer.WriteStartElement("People");
  
          writer.WriteStartElement("Person");
          writer.WriteAttributeString("Name", "Nick");
          writer.WriteEndElement();
  
          writer.WriteStartElement("Person");
          writer.WriteStartAttribute("Name");
          writer.WriteValue("Kevin");
          writer.WriteEndAttribute();
          writer.WriteEndElement();
  
          writer.WriteEndElement();
          writer.WriteEndDocument();
  
          writer.Flush();
  
          XmlDocument xmlDocument = new XmlDocument();
          xmlDocument.LoadXml(sb.ToString());
          return xmlDocument;
  
      }
  </code></pre>
  
  <p>In here, i create two methods to test the response. In GetXML, i create a very simple XML and return a package XML to client. </p>
  
  <p>In my client side: </p>
  
  <pre><code>    // Add button click function 
      protected void Button1_Click(object sender, EventArgs e)
      {
          string selectFlag = selectOper.Value;
          localhost.Service1 web = new localhost.Service1(); // Have to be the same name as youre Service1. 
          if (selectFlag.Equals("+"))
          {
              Result.Text = (web.addition(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();
          }
          else if (selectFlag.Equals("-"))
          {
              Result.Text = (web.subtract(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();
          }
  
      }
  
      protected void Button2_Click(object sender, EventArgs e)
      {
  
  
          localhost.Service1 web2 = new localhost.Service1(); // Can u please do not be so silly, use different instance name here. 
          Button clickedButton = (Button)sender;
  
          XmlDocument xmltest = new XmlDocument();
          xmltest = web2.GetXML();
  </code></pre>
  
  <p>You can see i tried to get web2.GetXML() get the whole XML into XmlDoucment. However, it said Error 1   Cannot implicitly convert type 'object' to 'System.Xml.XmlDocument'. An explicit conversion exists (are you missing a cast?)    C:\Documents and Settings\qili\My Documents\Downloads\WebService3\WebService2\WebService2\Default.aspx.cs   39  24  WebService2</p>
  
  <p>Any tips, i guess i am doing something wrong.  But the Buttom1_Click method is working fine. </p>