title: C#-WebService Soap Exception
body: <p>I am trying to retrieve a list of dropdown items from the database. The code works good if I am not using a Web Service to access the database, but when I used webservice to access the database, it gives me a Soap Exception. Here is the code, please help.</p>
  
  <p>The Exception is:</p>
  
  <pre><code>System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt;
  System.InvalidOperationException: There was an error generating the XML document. ---&gt;
  System.InvalidOperationException: Cannot serialize the DataTable. DataTable name is not set.
      at System.Data.DataTable.WriteXmlSchema(XmlWriter writer, Boolean writeHierarchy)
  </code></pre>
  
  <p>Here is the Method:</p>
  
  <pre><code>private void retrieveStates()
          {
              dataService = new PCDDA.Service();
              DataTable dt = new PCDDA.Service().GetStates();
              DDLSelectState.DataSource = dt;
              DDLSelectState.DataTextField = "RegionName";
              DDLSelectState.DataValueField = "RegionID";
              DDLSelectState.DataBind();
              DDLSelectState.Items.Insert(0, new ListItem("&lt;Select State&gt;", "0"));
          }
  </code></pre>
  
  <p>Here is the GetStates() Web Method which is in the Service.cs class of the Web Service:</p>
  
  <pre><code>[WebMethod]
      public DataTable GetStates()
      {
          DbPostcardOTR db = new DbPostcardOTR();
          try
          {
              DataTable loadstates = db.LoadStates();
              return loadstates;
  
          }
          catch (Exception ex)
          {
              throw new Exception("Unable to retrieve or load States from the database. The Exception is :" + ex.Message);
          }
  
      }
  </code></pre>
  
  <p>This is the LoadStates() Method in the DbPostcardOTR.cs:</p>
  
  <pre><code> public DataTable LoadStates()
      {
          DataTable States = new DataTable();
          SqlConnection con = OpenConnection();
          try
          {
              string selectSQL = "Select RegionID, RegionName from PCDDev.dbo.tblDistributionArea";
              SqlCommand cmd = new SqlCommand(selectSQL, con);
              SqlDataReader dr = cmd.ExecuteReader();
              States.Load(dr);
              return States;
          }
          finally
          {
              if (con != null)
                  con.Close();
          }
      }
  </code></pre>