【发布时间】:2012-03-03 07:44:26
【问题描述】:
我尝试根据 Simplest SOAP example
我可以通过此代码发送请求,但没有来自服务器的响应。我在下面给出的示例代码:
在此处输入代码
<html>
<head>
<title>SOAP call sample</title>
<script language="Javascript">
<!--
function xmlhttpPost() {
var symbol = "MSFT";
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "http://www.webservicex.net/stockquote.asmx?op=GetQuote",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4) {
alert("ready state callback:"+xmlhttp.readyState);
alert("response text or XML"xmlhttp.responseText);
var json = XMLObjectifier.xmlToJSON(xmlhttp.responseXML);
var result = json.Body[0].GetQuoteResponse[0].GetQuoteResult[0].Text;
json = XMLObjectifier.xmlToJSON(XMLObjectifier.textToXML(result));
alert(symbol + ' Stock Quote: $' + json.Stock[0].Last[0].Text);
}
}
xmlhttp.setRequestHeader("SOAPAction", "http://www.webserviceX.NET/GetQuote");
xmlhttp.setRequestHeader("Content-Type", "text/xml");
xmlhttp.setRequestHeader("POST","/stockquote.asmx HTTP/1.1");
xmlhttp.setRequestHeader("Host","www.webservicex.net");
xmlhttp.setRequestHeader("Content-Length",1000);
alert("setrequest header completed");
var xml = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body> ' +
'<GetQuote xmlns="http://www.webserviceX.NET/"> ' +
'<symbol>' + symbol + '</symbol> ' +
'</GetQuote> ' +
'</soap:Body> ' +
'</soap:Envelope>';
xmlhttp.send(xml);
alert("request sent"+xmlhttp);
}
//-->
</script>
</head>
<form name="main">
<table>
<tr>
<td> <input value="Submit to eBay => " type="button"
onclick='JavaScript:xmlhttpPost()'></td>
<td><textarea name="eBayXMLResponse" wrap="soft" rows="40" cols="50" style="overflow:scroll" ID="Textarea1"></textarea></td>
</tr>
</table>
</form>
</html>
我通过 Eclipse 和通过 apache-tomcat-7.0.25 应用服务器运行的动态 Web 项目尝试了这个示例。这足以运行这个示例吗? 请帮助我在浏览器控制台中显示响应。 我在这个问题上挣扎了一周.....如果有人对此有想法,请告诉我。
【问题讨论】:
-
也许你需要在客户端和服务器之间抓包,看看发生了什么。
-
你好,请告诉我要获得 SOAP 响应需要什么?
-
可能的原因有多种,1.请求没有发出; 2.服务器不工作; 3. 没有发出响应;数据包捕获将帮助您澄清您遇到的情况。
-
你能告诉我如何实现这个示例中的数据包捕获吗?
-
回调函数将 xmlhttp.readyState 返回为 4,即请求已完成且响应已就绪。但在我的代码中,xmlhttp.responseXML 值显示为 NULL。
标签: javascript web-services soap soapui soap-client