经典ASP中的SOAP问题
问题描述:
在http://www.lasertools.co.uk/webservice/getCatalogue.asmx有一个Web服务,我需要使用它接受SOAP 1.1和SOAP 1.2请求,但我没有经典的ASP经验;我已经阅读了几篇关于它的文章,并尝试了这些文章中提到的一些方法,但我似乎无法使其工作。到目前为止,我所管理的最好的服务器响应是404页面未找到。这里是我正在尝试的ASP页面:经典ASP中的SOAP问题
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<%
Dim objXML
Dim postUrl
Dim DataToSend
Dim DataParms
Dim DataReceived
Dim Status
DataToSend = ""
DataParms = ""
postUrl = "http://www.lasertools.co.uk/webservice/GetProductCategories"
Set objXML = CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "POST", postUrl, False
objXML.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXML.setRequestHeader "SOAPAction", "http://www.lasertools.co.uk/webservice/GetProductCategories"
objXML.setRequestHeader "MessageType", "CALL"
SOAPRequest = "<?xml version='1.0' encoding='utf-8'?> "
SOAPRequest = SOAPRequest & "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"""
SOAPRequest = SOAPRequest & " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"""
SOAPRequest = SOAPRequest & " xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
SOAPRequest = SOAPRequest & " <soap:Body>"
SOAPRequest = SOAPRequest & " <getProductCategories xmlns=""http://www.lasertools.co.uk/webservice"" />"
SOAPRequest = SOAPRequest & " </soap:Body>"
SOAPRequest = SOAPRequest & " </soap:Envelope>"
objXML.send SOAPRequest
DataReceived = objXML.responseText
Dim oXml
Set oXml = CreateObject("Msxml2.DOMDocument")
oXml.LoadXml (DataReceived)
oXML.async = False
Set objLst = oXml.getElementsByTagName("*")
if objLst.Length = 0 then
%>
<br />NO CHOICES<br />
<%
response.write DataReceived & "<br />"
else
AvailableChoices = 0
For Each xmlItem In objLst
For Each xmlItem2 In xmlItem.childNodes
if xmlItem.childNodes(0).NodeName = "#text" then
AvailableChoices = AvailableChoices + 1
DisplayVal = xmlItem.childNodes(0).text
%>
<%=DisplayVal%><br />
<%
end if
Next
Next
end if
%>
<body>
</body>
</html>
答
404响应是预期的;你没有张贴到正确的网址:
postUrl = "http://www.lasertools.co.uk/webservice/getCatalogue.asmx"
只需检查http://www.lasertools.co.uk/webservice/getCatalogue.asmx?op=getProductCategories上的示例。
当然,您发送的XML可能存在更多问题,但除非您使用mark it as code,否则此网站将删除括号内的任何内容。
哇,我简直不敢相信那么简单 - 我尝试了几十种代码组合!谢谢 – Mike 2011-03-05 12:42:07
没问题迈克。那么你能接受这个答案吗? (点击此答案左边的复选框)。 – Martijn 2011-03-05 12:43:52