ASP 调用返回 DataSet 的 Web Service
WebServiceDemo.asmx
public class ServiceDemo : WebService
{
[WebMethod]
public string HelloWorld(string ss)
{
return "Hello World,"+ss;
}
[WebMethod]
public DataSet GetStudents()
{
DataTable dt=new DataTable();
dt.Columns.Add("FID",typeof(string));
dt.Columns.Add("FName",typeof(string));
DataRow dr=dt.NewRow();
dr["FID"]="123";
dr["FName"]="wengmj";
dt.Rows.Add(dr);
DataRow dr1=dt.NewRow();
dr1["FID"]="456";
dr1["FName"]="cqm";
dt.Rows.Add(dr1);
DataSet ds=new DataSet();
ds.Tables.Add(dt);
return ds;
}
}
{
[WebMethod]
public string HelloWorld(string ss)
{
return "Hello World,"+ss;
}
[WebMethod]
public DataSet GetStudents()
{
DataTable dt=new DataTable();
dt.Columns.Add("FID",typeof(string));
dt.Columns.Add("FName",typeof(string));
DataRow dr=dt.NewRow();
dr["FID"]="123";
dr["FName"]="wengmj";
dt.Rows.Add(dr);
DataRow dr1=dt.NewRow();
dr1["FID"]="456";
dr1["FName"]="cqm";
dt.Rows.Add(dr1);
DataSet ds=new DataSet();
ds.Tables.Add(dt);
return ds;
}
}
Test.asp
<%
SET objSoapClient = Server.CreateObject("MSSOAP.SoapClient30")
objSoapClient.ClientProperty("ServerHTTPRequest") = True
call objSoapClient.MSSoapInit("http://localhost/Fredoc.Web/ServiceDemo.asmx?WSDL")
res = objSoapClient.HelloWorld("wengmj")
set stud= objSoapClient.GetStudents()
Set xmlDOC =CreateObject("MSXML2.DOMDocument.4.0")
xmlDOC.loadXML(stud.item(1).xml)
for each node in xmlDOC.firstChild.firstChild.childNodes
for each inode in node.childNodes
response.Write inode.text&" "
next
response.Write "<br>"
next
%>
SET objSoapClient = Server.CreateObject("MSSOAP.SoapClient30")
objSoapClient.ClientProperty("ServerHTTPRequest") = True
call objSoapClient.MSSoapInit("http://localhost/Fredoc.Web/ServiceDemo.asmx?WSDL")
res = objSoapClient.HelloWorld("wengmj")
set stud= objSoapClient.GetStudents()
Set xmlDOC =CreateObject("MSXML2.DOMDocument.4.0")
xmlDOC.loadXML(stud.item(1).xml)
for each node in xmlDOC.firstChild.firstChild.childNodes
for each inode in node.childNodes
response.Write inode.text&" "
next
response.Write "<br>"
next
%>