简体   繁体   中英

how to get dataset in delphi that generate in asp.net webservice

i wrote a webservice in asp.net that have select function that it's parameter is a string , return a dataset like this:

[WebMethod]
public DataSet Select(string query)
{
    DataTable dt = new DataTable();

    dt.Columns.Add("fname");
    dt.Columns.Add("lname");
    dt.Rows.Add("mehdi", "nine");
    dt.Rows.Add("ali", "javan");
    DataSet ds = new DataSet();
    ds.Tables.Add(dt);
    return ds;
}

when i see it's xml input it is like this:

<s:element name="Select">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="query" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="SelectResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="SelectResult">
<s:complexType>
<s:sequence>
<s:element ref="s:schema"/>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>

in xml file we can see it's output is SelectResult . how can i convert it to datasource in delphi7 ? any idea?

DaTaSet is not good As webservice return type for clients not using .net. You can try to retun XML here..

[WebMethod]
public string Select(string query)
{
    // your code
    return ds.GetXml();
}

This will give you XMl Like below

<NewDataSet>
  <Table1>
    <fname>mehdi</fname>
    <lname>nine</lname>
  </Table1>
  <Table1>
    <fname>ali</fname>
    <lname>javan</lname>
  </Table1>
</NewDataSet>

Hope that you can process this to use as DataSource.

If you need indented XML check this answer What is the simplest way to get indented XML with line breaks from XmlDocument?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM