参考一下  
   
  //****服务器端*******  
  Service1.asmx里包含下面两个WEBMETHOD  
  [WebMethod]  
  public   DataSet   GetMyProductsDataSet(int   userID)//被调用时将返回DATASET序列的XML,此XML主要用于ADO.NET  
  {  
  string   sql;  
  DataSet   ds2=new   DataSet();  
  sql   =   "select   userid,productname   from   StockIC   where   UserID="+userID;  
  my_adapter   =   new   SqlDataAdapter(sql,this.sqlConnection1);  
  my_adapter.Fill(ds2,"Stock");  
  return   ds2;  
  }  
   
  [WebMethod]  
  //被调用时将返回ADO.Recodset序列的XML  
  public   System.Xml.XmlDocument   GetMyProductsRecordSet(int   userID),此XML主要用于ADO  
  {  
  string   sql;  
  ADODB.Recordset   rs=new   ADODB.Recordset();  
  ADODB.Stream   st=new   ADODB.Stream();  
  System.Xml.XmlDocument   xd=new   System.Xml.XmlDocument();  
  sql   =   "select   userid,productname   from   StockIC   where   UserID="+userID;  
  rs.Open(sql,this.sqlConnection3,ADODB.CursorTypeEnum.adOpenForwardOnly,ADODB.LockTypeEnum.adLockReadOnly,   1);  
  rs.Save(st,ADODB.PersistFormatEnum.adPersistXML);  
  st.Flush();  
  st.Position=0;  
  xd.LoadXml(st.ReadText(st.Size));  
  return   xd;  
  }  
   
   
   
  '****客户端*******  
  'XMLHTTP调用并装载到ADO.RECORDSET分析(简单方便),可以直接由XMLDOM来分析  
   
  Set   objHTTP   =   Server.CreateObject("MSXML2.XMLHTTP.4.0")  
  Set   objXmlDoc   =Server.CreateObject("MSXML2.DOMDocument.3.0")  
  strWebserviceURL   =   "http://192.168.1.88/Service1.asmx/GetMyProductsRecordSet"  
  strRequest   =   "userID=43"  
  objHTTP.Open   "post",   strWebserviceURL,   False  
  objHTTP.SetRequestHeader   "Content-Type",   "application/x-www-form-urlencoded"  
  objHTTP.Send(strRequest)  
  objXmlDoc.load   objHTTP.responseXML  
  set   rs=server.CreateObject("adodb.recordset")  
  rs.Open   objXmlDoc'必须是ADO.Recodset序列的XML,如果上面http://192.168.1.88/Service1.asmx调用的方法GetMyProductsRecordSet改成GetMyProductsDataSet将报错  
  if   rs   is   nothing   then   response.Write   "rsisnothing"  
  if   rs.EOF   then  
  response.Write   "rs.EOF"  
  else  
  while   not   rs.EOF    
  response.Write   rs(0)   &   "<br/>"  
  rs.MoveNext  
  wend  
  end   if  
  set   objXmlHttp=nothing  
  set   objXmlDoc=nothing  
  set   rs=nothing
posted on 2008-09-02 04:54  睿达团队  阅读(2184)  评论(0编辑  收藏  举报