如何在AJAX调用中使用SOAP请求
这是我的AJAX应用程序,我需要在其中联系服务器中运行的Web服务如何在AJAX调用中使用SOAP请求,ajax,soap,Ajax,Soap,这是我的AJAX应用程序,我需要在其中联系服务器中运行的Web服务 function sendRequest(method, url) { method == 'post'; { http.open(method,url,true); http.onreadystatechange = handleResponse; http.send(null); } } 这是我从soapui中获取的SOAP请求,它工作正常 <soapenv:Envelope xmlns:soapenv="http:
function sendRequest(method, url)
{
method == 'post';
{
http.open(method,url,true);
http.onreadystatechange = handleResponse;
http.send(null);
}
}
这是我从soapui中获取的SOAP请求,它工作正常
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.bayer.tata.com/" xmlns:tkw="http://tata.com/bayer" xmlns:chim="http://tata.com/chimera">
<soapenv:Header/>
<soapenv:Body>
<ser:strategy>
<!--Optional:-->
<request>
<xmlMessage>
<![CDATA[<test>or like this</test>]]>
</xmlMessage>
</request>
</ser:strategy>
</soapenv:Body>
</soapenv:Envelope>
请告诉我如何在sendRequest函数中使用此SOAP XML消息。
我只使用普通的Java脚本AJAX,没有任何东西像Jquery、DOJO或任何我认为可以帮助您的东西。但是,如果请求不需要SOAP头或其他奇怪的东西,大多数web服务器允许您在主体请求中使用纯HTTP Post调用web服务,而不使用SOAP格式
NET和纯javaScript中的一个示例:
.NETWeb服务
<System.Web.Services.WebService(Namespace:="http://JuntaEx/Agricultura/SegurInfo/GestorFirmaExterno/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class GestorFirmaExterno
Inherits System.Web.Services.WebService
<WebMethod(Description:="Retorna los documentos originales asociados a un identificador de firma pasado como parámetro.")> _
Public Function ObtenerDocumentoOriginal(ByVal idFirma As String) As DocumentoED()
//code
End Function
End Class
将此请求发送到服务器:
POST /wsGestorFirmaExterno/GestorFirmaExterno.asmx/ObtenerDocumentoOriginal HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
idFirma=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfDocumentoED xmlns="http://JuntaEx/Agricultura/SegurInfo/GestorFirmaExterno/">
<DocumentoED>
<hash>string</hash>
</DocumentoED>
<DocumentoED>
<hash>string</hash>
</DocumentoED>
</ArrayOfDocumentoED>
并从服务器接收此响应:
POST /wsGestorFirmaExterno/GestorFirmaExterno.asmx/ObtenerDocumentoOriginal HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
idFirma=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfDocumentoED xmlns="http://JuntaEx/Agricultura/SegurInfo/GestorFirmaExterno/">
<DocumentoED>
<hash>string</hash>
</DocumentoED>
<DocumentoED>
<hash>string</hash>
</DocumentoED>
</ArrayOfDocumentoED>
使用javascript解析它以获得所需的信息
PS:您可以将服务器和浏览器请求配置为发送和接收JSON数据,而不是XML
我希望这能有所帮助。感谢您的时间和回复,但我还是很困惑,我对Java相关技术很感兴趣,您能告诉我AJAX请求中您实际使用SOAP请求的位置吗?这就是重点。我没有使用SOAP请求。我正在使用javascript来使用web服务,而不使用所有SOAP内容。我只是告诉您,也许您不需要使用SOAP来请求Web服务。只是建议一个不同的方法。不管怎样,你检查了我答案顶部的链接了吗?它解释了您想要了解的关于javascript中SOAP的所有内容。