title: C# .net Web Service Web Method Returning &lt; and &gt; in View Source
body: <p>I have a stored procedure returning a datatable with a stored procedure in a Web Service Web Method.  I'm trying to then convert the datatable to XML, however, when I view source of the returned XML (Which looks fine in the browser window) instead of &lt;> it's returning <code>&amp;lt;</code> and <code>&amp;gt;</code> around the XML nodes.</p>
  
  <p>I've looked at the similar questions and I <strong>have</strong> tried using <strong>HTMLEncode</strong> or <strong>HTMLDecode</strong> to no avail.</p>
  
  <p>Here is my Web Service Code.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Data.SqlClient;
  using System.Text;
  using System.Web;
  using System.Web.Services;
  using System.Xml;
  
  namespace DAL
  {
      [WebService(Namespace = "http://tempuri.org/")]
      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
      [System.ComponentModel.ToolboxItem(false)]
  public class iPhoneWebServices : System.Web.Services.WebService
  {
      [WebMethod(Description="Return All Current Makes")]
      public string ReturnMakes()
      {
          // Get All Records with NAME Parameter
          DataTable dataTable = DataAccessLayer.ExecuteDataTable("ipa_ReturnMakes");
  
          StringBuilder sbrXML = new StringBuilder();
  
          if (dataTable.Rows.Count &gt; 0)
          {
              sbrXML.AppendLine("&lt;MakeList&gt;");
  
              foreach (DataRow objRow in dataTable.Rows)
              {
                  sbrXML.AppendLine("&lt;Make&gt;&lt;MakeID&gt;[makeID]&lt;/MakeID&gt;&lt;MakeName&gt;[makeName]&lt;/MakeName&gt;&lt;/Make&gt;");
                  sbrXML.Replace("[makeID]", objRow["MakeID"].ToString());
                  sbrXML.Replace("[makeName]", objRow["MakeName"].ToString());
              }
              sbrXML.AppendLine("&lt;/MakeList&gt;");
          }
          else
          {
              // no data
              sbrXML.AppendLine("&lt;makeList&gt;");
              sbrXML.AppendLine("no data");
              sbrXML.AppendLine("&lt;/makeList&gt;");
          }
          return sbrXML.ToString();
      }
  
      //Return Models From Make ID
      [WebMethod(Description="Returns Models From Make ID")]
      public string ReturnModels(int MakeID)
      {
  
          SqlParameter[] param = new SqlParameter[1];
          param[0] = new SqlParameter("MakeID", SqlDbType.Int);
          param[0].Value = MakeID;
  
          // Get All Records with NAME Parameter
          DataTable dataTable = DataAccessLayer.ExecuteDataTable("ipa_ReturnModelsForMake", param);
  
          StringBuilder sbrXML = new StringBuilder();
  
          if (dataTable.Rows.Count &gt; 0)
          {
              sbrXML.AppendLine("&lt;ModelList&gt;");
  
              foreach (DataRow objRow in dataTable.Rows)
              {
                  sbrXML.AppendLine("&lt;Model&gt;&lt;ModelID&gt;[modelID]&lt;/ModelID&gt;&lt;ModelName&gt;[modelName]&lt;/ModelName&gt;&lt;/Model&gt;");
                  sbrXML.Replace("[modelID]", objRow["ModelID"].ToString());
                  sbrXML.Replace("[modelName]", objRow["ModelName"].ToString());
              }
              sbrXML.AppendLine("&lt;/ModelList&gt;");
          }
          else
          {
              // no data
              sbrXML.AppendLine("&lt;ModelList&gt;");
              sbrXML.AppendLine("no data");
              sbrXML.AppendLine("&lt;/ModelList&gt;");
          }
          return sbrXML.ToString();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>What it's returning in the view source for Web Method "ReturnModels"</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;string xmlns="http://tempuri.org/"&gt;&amp;lt;ModelList&amp;gt;
  &amp;lt;Model&amp;gt;&amp;lt;ModelID&amp;gt;20945&amp;lt;/ModelID&amp;gt;&amp;lt;ModelName&amp;gt;Anglia&amp;lt;/ModelName&amp;gt;&amp;lt;/Model&amp;gt; 
  &amp;lt;Model&amp;gt;&amp;lt;ModelID&amp;gt;11006&amp;lt;/ModelID&amp;gt;&amp;lt;ModelName&amp;gt;Transit&amp;lt;/ModelName&amp;gt;&amp;lt;/Model&amp;gt;
  &amp;lt;Model&amp;gt;&amp;lt;ModelID&amp;gt;21952&amp;lt;/ModelID&amp;gt;&amp;lt;ModelName&amp;gt;Zodiac Mark III&amp;lt;/ModelName&amp;gt;&amp;lt;/Model&amp;gt;
  &amp;lt;/ModelList&amp;gt;
  &lt;/string&gt;
  </code></pre>
  
  <p>It is showing properly in the browser window:</p>
  
  <pre><code>&lt;string&gt;
  &lt;ModelList&gt;
  &lt;Model&gt;&lt;ModelID&gt;20945&lt;/ModelID&gt;&lt;ModelName&gt;Anglia&lt;/ModelName&gt;&lt;/Model&gt;
  &lt;Model&gt;&lt;ModelID&gt;15881&lt;/ModelID&gt;&lt;ModelName&gt;C-Max&lt;/ModelName&gt;&lt;/Model&gt;
  &lt;Model&gt;&lt;ModelID&gt;20303&lt;/ModelID&gt;&lt;ModelName&gt;Capri&lt;/ModelName&gt;&lt;/Model&gt;
  &lt;Model&gt;&lt;ModelID&gt;11006&lt;/ModelID&gt;&lt;ModelName&gt;Transit&lt;/ModelName&gt;&lt;/Model&gt;
  &lt;Model&gt;&lt;ModelID&gt;21952&lt;/ModelID&gt;&lt;ModelName&gt;Zodiac Mark III&lt;/ModelName&gt;&lt;/Model&gt;
  &lt;/ModelList&gt;
  &lt;/string&gt;
  </code></pre>
  
  <p>Just need to get what's showing in the browser window into the view source as well.</p>
  
  <p>Thank you for your help and time in advance!</p>