我正在用JS创建一个SOAP客户端,这是我第一次使用web服务,并且我的代码中必须有几个错误。创建一个JavaScript SOAP客户端
poit是,用我的代码,我无法访问到WebService,但我不知道如何访问里面的方法。所以web服务给我以下的回应:
<h1>Version</h1>
<p>Hi there, this is an AXIS service!</p>
<i>Perhaps there will be a form for invoking the service here...</i>
而不是正在调用的方法正确的XML。
这是我的SOAP客户端的代码:
<html>
<script type="text/javascript">
function run(){
var objXMLHttpRequest = new XMLHttpRequest();
objXMLHttpRequest.open("GET", "http://localhost:8080/CrunchifyWS/services/Version?wdsl/", true);
objXMLHttpRequest.onreadystatechange = function() {
//alert(objXMLHttpRequest.readyState+" "+ objXMLHttpRequest.status);
if (objXMLHttpRequest.readyState == 4 && objXMLHttpRequest.status == 200) {
result = objXMLHttpRequest.responseXML;
alert(objXMLHttpRequest.responseText);
alert(objXMLHttpRequest.responseXML);
}
}
objXMLHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
var packet = '<?xml version="1.0" encoding="utf-8" ?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><getVersion xmlns="http://service.web.com.crunchify/"></getVersion></soap:Body></soap:Envelope>';
objXMLHttpRequest.send(packet);
// Add mentioned below code only if your application calls webservice synchronously. Otherwise use "onreadystatechange" process response.
response = objXMLHttpRequest.responseXML;
alert(objXMLHttpRequest.responseText+ " "+ response);
}
</script>
<head>
</head>
<body>
<button onclick="run()">Dale!</button>
</body>
</html>
我认为TE的错误应该是在部分,但是,正如我所说,这是我第一次,我不知道我正在做。
解决
我对角读取,但尝试“POST”而不是“GET”?大多数肥皂终点是仅邮政。 – nablex 2015-04-01 10:05:11
当尝试POST而不是GET我有 <?xml version =“1.0”encoding =“UTF-8”?> NS1:Client.NoSOAPAction 没有SOAPAction头 faultstring> WebServices-PC ns2:hostname> soapenv:Fault> soapenv :Body> soapenv:Envelope> –
LokiNkc
2015-04-01 10:12:19
是的,在SOAP 1.1版本中,您需要添加一个soapaction。这个soapaction可以从WSDL中获取,并且必须作为HTTP头传入。 – nablex 2015-04-01 10:15:47