asp 訪問WebService 基於SOAP

來源:互聯網
上載者:User

<%
'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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.