Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi everybody

I need to convert every item of this web service result to a dataTable

HTML
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://bluxxx.xxxxxxxxs.net/LFA/confirmRcv3.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <SOAP-ENV:Body>
      <ns1:ControlreciboResponse>
         <return SOAP-ENC:arrayType="xsd:string[6]" xsi:type="SOAP-ENC:Array">
            <item xsi:type="xsd:string"><![CDATA[<item><TipoDocto>OCN</TipoDocto>
                     <Documento>39147</Documento>
                     <Codigo>17429</Codigo>
                     <Cantidad_Recibida>12</Cantidad_Recibida>
                     <Estatus>Disponible</Estatus></item></item>
            <item xsi:type="xsd:string"><![CDATA[<item><TipoDocto>OCN</TipoDocto>
                     <Documento>39147</Documento>
                     <Codigo>32757</Codigo>
                     <Cantidad_Recibida>13</Cantidad_Recibida>
                     <Estatus>Disponible</Estatus></item></item>
            <item xsi:type="xsd:string"><![CDATA[<item><TipoDocto>OCN</TipoDocto>
                     <Documento>39147</Documento>
                     <Codigo>48156</Codigo>
                     <Cantidad_Recibida>6</Cantidad_Recibida>
                     <Estatus>Disponible</Estatus></item></item>
            <item xsi:type="xsd:string"><![CDATA[<item><TipoDocto>OCN</TipoDocto>
                     <Documento>39147</Documento>
                     <Codigo>52314</Codigo>
                     <Cantidad_Recibida>7</Cantidad_Recibida>
                     <Estatus>Disponible</Estatus></item></item>
            <item xsi:type="xsd:string"><![CDATA[<item><TipoDocto>OCN</TipoDocto>
                     <Documento>39147</Documento>
                     <Codigo>55327</Codigo>
                     <Cantidad_Recibida>10</Cantidad_Recibida>
                     <Estatus>Disponible</Estatus></item></item>
            <item xsi:type="xsd:string"><![CDATA[<item><TipoDocto>OCN</TipoDocto>
                     <Documento>39147</Documento>
                     <Codigo>57813</Codigo>
                     <Cantidad_Recibida>6</Cantidad_Recibida>
                     <Estatus>Disponible</Estatus></item></item>
         </return>
      </ns1:ControlreciboResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


This is My procedure is

C#
private void btnLecturaBLur_Click(object sender, EventArgs e)
{
    //get the web service method
     recibodlxService serviceProxy = new recibodlxService();

     object[] sXmlProp = serviceProxy.Controlrecibo();

    //create the datatable
    DataTable dtx;

     //create the datarow
    DataRow dr = dtx.NewRow();
     foreach (object item in sXmlProp)
     {
         //here, HOW Do I do TO add an item to a row
     }

     dtx.Rows.Add(dr);


Or, can I use dataTable
C#
dtx.ReadXml(reader)
??

What I have tried:

I´m Tried to do something like this:

C#
PropertyInfo[] Prop = serviceProxy.Controlrecibo().GetType().GetElementType().GetProperties();
  DataTable dt = CreateDataTable(Prop);
  DataRow dr = dt.NewRow();

  foreach (PropertyInfo pi in Prop)
  {
      dr[pi.Name] = pi.GetValue(sXmlProp, null);
  }
  dt.Rows.Add(dr);

the error that shows me is "The object does not match with the target type."
Posted
Updated 6-Jul-16 6:39am

1 solution

when you add the webservice as web reference, visual studio automatically genereta the objects that are the "containers" for the data the webservice returns. you dont need to parse the xml by your self. identify those objects, call the webservice to fill them, they will be a Collection that you iterate item by item like this:

foreach (ControlreciboResponse item in ControlreciboResponseCollection){

DataRow dr = new DataRow()
dr[0].value =item.TipoDocto;
dr[1].value =item.Documento;
dr[2].value =item.Codigo;
etc...
dt.Rows.Add(dr);
}

regards.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900