asp 訪問WebService 基於SOAP

<%
'strTableName 表名
'strField 字段名稱
'strWhere 條件
'nFlag 命令參數,0:添加,1:修改,2:刪除
 function getWebServiceData(strTableName,strField,strWhere,nFlag) 
 'url="http://192.168.1.160/usercenter3/LogonWS.asmx?methodname=KLManagerDataBase"
 url="http://"&ipaddress&"/LogonWS.asmx"
  dim xmlStr
    set xmlhttp = server.createobject("msxml2.xmlhttp")
   UserName="CNSEC.net"
   PassWord="20080512"
   strYDKey="cnsec20080512"
      soaprequest="<?xml version="&CHR(34)&"1.0"&CHR(34)&" encoding="&CHR(34)&"utf-8"&CHR(34)&"?>"& _
   "<soap:Envelope xmlns:xsi="&CHR(34)&"http://www.w3.org/2001/XMLSchema-instance"&CHR(34)&" "& _
   "xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _
   "xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _
   "<soap:Header>"&_
   "<CredentialSoapHeader xmlns="&CHR(34)&"http://www.cnsec.com/"&CHR(34)&">"&_
   "<UserName>"&UserName&"</UserName>"&_
   "<PassWord>"&PassWord&"</PassWord>"&_
   "</CredentialSoapHeader>"&_
   "</soap:Header>"&_
   "<soap:Body>"& _   
   "<KLManagerDataBase xmlns="&CHR(34)&"http://www.cnsec.com/"&CHR(34)&">"& _     
   "<strTableName>"&strTableName&"</strTableName>"& _
   "<strField>"& strField &"</strField>"& _
   "<strWhere>"&strWhere&"</strWhere>"&_
   "<nFlag>"&nFlag&"</nFlag>"&_
   "<strYDKey>"&strYDKey&"</strYDKey>"& _
   "</KLManagerDataBase>"& _   
   "</soap:Body>"& _
   "</soap:Envelope>"
   
    xmlhttp.open "post",url,false  
    xmlhttp.setrequestheader "content-type", "text/xml; charset=utf-8"
    xmlhttp.setrequestheader "host",ipaddress
    xmlhttp.setrequestheader "Content-Length",len(soaprequest)
    xmlhttp.setRequestHeader "SOAPAction", "http://www.cnsec.com/KLManagerDataBase"
    xmlhttp.send(soaprequest)
   if xmlhttp.status = 200 then
   Set xmlDOC =server.CreateObject("MSXML.DOMDocument")
   xmlDOC.load(xmlhttp.responseXML)
   xmlStr = xmlDOC.documentElement.selectNodes("//KLManagerDataBaseResult")(0).text   
   xmlStr = Replace(xmlStr,"<","&lt;")
   xmlStr = Replace(xmlStr,">","&gt;")
   getWebServiceData=xmlStr
   response.Write(xmlStr)
   Set xmlDOC=nothing
  else
   response.Write("<font color='red'>狀態:"&xmlhttp.status&"</font>")
   response.Write("<script language='javascript'>alert('請求WebService 出錯了,請聯繫管理員!狀態:"&xmlhttp.status&"');window.history.go(-1)</script>")
  end if
   set xmlhttp = nothing
 end function

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章