我每天使用标准HTML&编写代码。经典ASP。我被要求构建一个小API,它将使用我们的ASP / html平台和SQL Server数据库。我可以毫不费力地处理ASP / SQL Server,HTML等。我甚至可以编写XML请求来查询我们的服务器。但我不知道从哪里开始设置服务来“监听”入站XML请求。我准备了大约十几个请求/响应例程,但不知道如何编写接收该请求的页面的代码。
那里的任何人都可以提供帮助吗?
例如:
我们要求的一个方法/函数是一个简单的Category List请求。使用SOAP,我可以使请求很好,只是我不知道如何在服务器上形成接收方来接受请求并做出响应。
我已经提出了以下请求,我只需要知道如何处理Web服务页面以接收此请求并响应数据。任何帮助将不胜感激。请参阅下文。
要发送的VAR
DealerID
UserID
Password
Dept
代码:
DIM wagConnect, WAGRequest
wagConnect = "http://www....../catreq.asp"
Dim strResult, strNamespace, strFunction
DIM wagResponse, xmldom, xmlresponse
Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")
' strNamespace="urn:externalwsdl"
' strFunction="add_line"
' area_code
WAGRequest = "<?xml version=""1.0"" encoding=""utf-8"" ?>" & _
"<soapenv:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soapenv:Body>" & _
"<Get_Categories xmlns=""urn:externalwsdl"">" & _
"<DealerInfo>" & _
"<DealerID>DealerTest</DealerID>" & _
"<UserID>K850</UserID>" & _
"<Password>1234567Pass</Password>" & _
"</DealerInfo>" & _
"<CatInfo>" & _
"<Dept></Dept>" & _
"</CatInfo>" & _
"</Get_Categories>" & _
"</soapenv:Body>" & _
"</soapenv:Envelope>"
objXMLHTTP.open "POST", "" & wagConnect & "", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=UTF-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(WAGRequest)
'objXMLHTTP.setRequestHeader "SOAPMethodName", strFunction
objXMLHTTP.setRequestHeader "SOAPAction", wagConnect
'strNamespace & "#" & strFunction
'send the request and capture the result
Call objXMLHTTP.send(WAGRequest)
xmlresponse = objXMLHTTP.responsetext
wagResponse = ("<pre>"& replace(replace(xmlresponse, "<", "<"), ">", "><br>") &"</pre>")
Set xmldom = Server.CreateObject("Microsoft.XMLDOM")
xmldom.async = false
xmldom.loadxml(objXMLHTTP.responsexml.xml)
IF objXMLHTTP.status <> 200 THEN
wagResponse = "Could not get XML data."
END IF
'Response elements and attributes
'Result-Code (1 = Success, 0 = Failed)
'Category Count {Cat_Count, int} (Number of Categories returned)
'Category
'Child elements: 'CatName {Cat_Name, nvarchar} (Short Text)
'Category Subtitle {Cat_Desc, nvarchar} (SubTitle)
'Category Desc {Cat_Memo, ntext} (long description)
'Picture URL {Cat_Pic, ntext} (URL)'
'ResultCode = xmldom.getElementsByTagName("result-code")(0).text
If ResultCode = 1 THEN
CatCnt = xmldom.getElementsByTagName("Cat_Count")(0).text
CatName = xmldom.getElementsByTagName("Cat_Name")(0).text
CatDesc = xmldom.getElementsByTagName("Cat_Desc")(0).text
CatMemo = xmldom.getElementsByTagName("Cat_Memo")(0).text
CatPic = xmldom.getElementsByTagName("Cat_Pic")(0).text
End if
感谢您的帮助!
答案 0 :(得分:1)
你应该简单地创建一个脚本,通过POST以xml格式获取指令。然后脚本应该从发布的xml内容中检索其变量,然后生成一个xml输出并通过response.write()
轻松发送