ASP.NET - Xml OverHttpRequest in asp.net not working properly

Asked By Daniel on 19-Feb-13 06:52 AM
Hi I am passing this xml content as parameter to get a response:
 <COMMAND>
                <TYPE>PAYMENT</TYPE>
                <COMPANYNAME>gemeya</COMPANYNAME>
                <CUSTOMERREFERENCEID>910573404</CUSTOMERREFERENCEID>
                <MSISDN>msisdn</MSISDN>
                <AMOUNT>45150.00</AMOUNT>
                <TXNID></TXNID>
                <STATUS></STATUS>
    </COMMAND>

from a webservice but I am getting this error :
System.IndexOutOfRangeException: Cannot find table 0.
   at System.Data.DataTableCollection.get_Item(Int32 index)
  
And the following code is what I am using to test it with information from my db:
SP:
01.ALTER PROCEDURE [dbo].[GetCheckoutInfoTest]
02.@Refcode nvarchar(100)
03.,@Amount nvarchar(100)
04.AS
05. BEGIN
06.  DECLARE @Price AS float
07.  DECLARE @RefId AS int
08.  DECLARE @TXTNID AS NVARCHAR(50)
09.  DECLARE @companyname AS NVARCHAR(50)
10.    
11.  SET @Price=(SELECT Amount FROM Checkout  Where Refcode=@Refcode)
12.  SET @RefId=(SELECT Refcode FROM Checkout WHERE Refcode=@Refcode)
13.  SET @TXTNID='GBPHANDLER'
14.  SET @companyname='Gemeya'
15.  if exists(SELECT Amount,Refcode FROM Checkout  Where Refcode=@Refcode)
16.    begin
17.    if(@Amount=@Price and @RefId=@Refcode)
18.    begin
19.      PRINT N'Your transaction successfull. Txn ID:'+ @TXTNID +', reference: '+
20.      @Refcode +', amount :'+ @Amount +' Tsh, Company: '+ @companyname;
21.     return 1
22.    end
23.    end
24.    else
25.    begin
26.     PRINT N'Your transaction Failed';
27.    return 0
28.    end
29. END
in the chekout table I have data... And this is the class I am using CS:
01.public class Service : System.Web.Services.WebService
02.{
03.  public int Amount { get; set; }
04.  public int Refcode { get; set; }
05.  public int companycode { get; set; }
06.  public bool IsUsed { get; set; }
07.  public string PhoneNo { get; set; }
08.   #region method constructor
09.  public Service()
10.  {
11.     //Uncomment the following line if using designed components
12.    //InitializeComponent();
13.  }
14.  #endregion
15.  [WebMethod]
16.  public string COMMAND(string xml)
17.  {
18.    #region Load received xml and parse the values
19.    XmlDocument xdoc = new XmlDocument();
20.    xdoc.LoadXml(xml + Environment.NewLine);
21.    string TYPE = xdoc["COMMAND"].ChildNodes[0].InnerText;
22.    string COMPANYNAME = xdoc["COMMAND"].ChildNodes[1].InnerText;
23.    string CUSTOMERREFERENCEID = xdoc["COMMAND"].ChildNodes[2].InnerText;
24.    string MSISDN = xdoc["COMMAND"].ChildNodes[3].InnerText;
25.    string AMOUNT = xdoc["COMMAND"].ChildNodes[4].InnerText;
26.    string TXNID = xdoc["COMMAND"].ChildNodes[5].InnerText;
27.    string STATUS = xdoc["COMMAND"].ChildNodes[6].InnerText;
28.    #endregion
29.     string ERRORCODE = string.Empty;
30.    string RESULT = string.Empty;
31.    string FLAG = string.Empty;
32.    string CONTENT = string.Empty;
33.    //process your code with received information and assign the values of ERRORCODE,RESULT,FLAG,CONTENT
34.    StringBuilder sb = new StringBuilder();
35.    DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), "[GetCheckoutInfoTest]"
36.    CUSTOMERREFERENCEID,AMOUNT);
37.    if (ds.Tables[0].Rows.Count > 0)
38.    {
39.      //assign the values of ERRORCODE,RESULT,FLAG,CONTENT when condition is true
40.      RESULT = "TS";
41.    }
42.    else
43.    {
44.      //assign the values of ERRORCODE,RESULT,FLAG,CONTENT when condition is false
45.      RESULT = "TF";
46.    }
47. 
48. 
49.    #region write the response xml
50.    XmlWriter writer = XmlWriter.Create(sb);
51. 
52. 
53.      writer.WriteStartDocument();
54.      writer.WriteStartElement("COMMAND");
55.      writer.WriteStartElement("TYPE");
56.      writer.WriteValue(TYPE);
57.      writer.WriteEndElement();
58.      writer.WriteStartElement("TXNID");
59.      writer.WriteValue(TXNID);
60.      writer.WriteEndElement();
61.      writer.WriteStartElement("REFID");
62.      writer.WriteValue(CUSTOMERREFERENCEID);
63.      writer.WriteEndElement();
64.      writer.WriteStartElement("ERRORCODE");
65.      writer.WriteValue(ERRORCODE);
66.      writer.WriteEndElement();
67.      writer.WriteStartElement("FLAG");
68.      writer.WriteValue(FLAG);
69.      writer.WriteEndElement();
70.      writer.WriteStartElement("MSISDN");
71.      writer.WriteValue(MSISDN);
72.      writer.WriteEndElement();
73.      writer.WriteStartElement("CONTENT");
74.      writer.WriteValue(CONTENT);
75.      writer.WriteEndElement();
76.      writer.WriteStartElement("COMPANYCODE");
77.      writer.WriteValue(COMPANYNAME);
78.      writer.WriteEndElement();
79.      writer.WriteStartElement("AMOUNT");
80.      writer.WriteValue(AMOUNT);
81.      writer.WriteEndElement();
82.      writer.WriteEndElement();
83.      writer.WriteEndDocument();
84.      writer.Flush();
85.      #endregion
86.   return sb.ToString();
87.    }
After debug I am getting an error(System.IndexOutOfRangeException) on the line 35. Please help fixing this