asp llama a la interfaz del servicio web a través de json y obtiene los datos y análisis xml devueltos

En este caso, asp llama a la interfaz del servicio web y obtiene los datos y análisis XML devueltos.


<! - # include file = "conn.asp" ->
<! - # include file = "md532.asp" ->

<! - # include file = "SYS_INCLUDE_HTML.ASP" ->

<%   
Response.Write "Test time:" & now () & "<br>"
dim url, SOAPAction, HOST
url = "http://192.168.17.71/KDWebservice/KDService.asmx?op=CreateCust" // webserbiceaddress = number Seguido por el método de la interfaz
Host = "192.168.17.71" // dirección IP
SOAPAction = "http://tempuri.org/CreateCust" // reemplace CreateCust con su método

dim stringJS
custno = request ("custno")
key = " 16394 "
strtoken = custno y clave
token = md5 (strtoken, 32,



sql = "select * from [customer] donde custno = '" & custno & "'"
rs.open sql, conn, 1,1
si no es rs.ef entonces
    noCustNo = rs ("custno")
    fCustName = rs ("cmingcheng")
finalizar si
rs.close

stringJS = "{'token': '" & token & "', 'head': {'fCustNo': '" & fCustNo & "', 'fCustName': '" & fCustName & "'}}" // 这 是Son 获取 数据 拼接 的 json, 可以 替换 你 自己 的 json
Response.Write stringJS & "<br>"


SoapRequest = "<? Xml version =" & CHR (34) & "1.0" & CHR (34) & "encoding =" & CHR (34) y "utf-8" y CHR (34) y "?>" & _
"<soap: Envelope xmlns: xsi =" & CHR (34) & "http://www.w3.org/2001/XMLSchema-instance" & CHR (34) & "" & _
"xmlns: xsd =" & CHR ( 34) y "http://www.w3.org/2001/XMLSchema" y CHR (34) y "" y _
"xmlns: soap =" & CHR (34) & "http://schemas.xmlsoap.org/soap/envelope/" & CHR (34) & ">" & _
"<soap: Body>" & _
"<CreateCust xmlns = "& CHR (34) &" http://tempuri.org/ "& CHR (34) &"> "& _ // 把 CreateCust 替换 你 的 方法
" <json> "& stringJS &" </json> "& _   
" </CreateCust> "& _ // 把 CreateCust 替换 你 的 方法
" </ soap: Body> "& _
" </ soap: Envelope> "

Set xmlhttp = server.CreateObject (" Msxml2.XMLHTTP ")
xmlhttp.Open" POST ", url, false
xmlhttp.setRequestHeader" Content-Type "," text / xml; charset = utf-8 "
xmlhttp.setRequestHeader "HOST", Host
xmlhttp.setRequestHeader "Content-Length", LEN (SoapRequest)
xmlhttp.setRequestHeader "SOAPAction", SOAPAction

// 'Debe ser el mismo que el espacio de nombres WEBSERVICE, de lo contrario, el servicio será rechazado   


xmlhttp.Send (SoapRequest)
   
// 'Esto usará XMLHTTP para enviar con éxito una solicitud SOAP que coincida con el ejemplo SOAP.   
//' Verifique si es exitosa:   
Response.Write "Status:" & xmlhttp.Status & "<BR>"
Response. Escriba "StatusText:" & xmlhttp.StatusText & "<BR>"

si xmlhttp.status = 200      
    establezca xmldoc = server.createobject ("msxml2.domdocument")     
    xmldoc.load (xmlhttp.responsexml)
    // xmldoc es devuelto por el servicio web contenido xml, si el servicio web no devuelve xml, use xmlhttp.responsetext
    
    objNodes = xmldoc.getElementsByTagName ("root / msgType")
     Response.Write "Status:" & objNodes & "<BR>"
     
     sendMessageByPhone = xmldoc.documentElement.selectNodes (" //root//msgType")(0).text // analizar xml root primer nodo msgType segundo nodo
    Response.Write "msgType :" & sendMessageByPhone & "<BR>"
    
    sendMessageByPhone = xmldoc.documentElement.selectNodes ("// root // msgstring") (0) .text
    Response.Write "msgstring :" & sendMessageByPhone & "<BR>"
            
más
    Respuesta .Escribe "调用 webservice 失败" y
finaliza si

    
Set xmlhttp = Nothing   

%>   


21 artículos originales publicados · 21 alabanzas · 40,000+ vistas

Supongo que te gusta

Origin blog.csdn.net/kuyz1/article/details/54585039
Recomendado
Clasificación