2011-12-15 5 views
0

이것은 서버에서 실행중인 웹 서비스에 연락해야하는 AJAX 응용 프로그램입니다. AJAX 호출 내에서 SOAP 요청을 사용하는 방법

function sendRequest(method, url) 
{ 
method == 'post'; 
{ 
http.open(method,url,true); 
http.onreadystatechange = handleResponse; 
http.send(null); 
} 
} 

내가 잘 작동 한,는 SOAP UI에서 주워 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 메시지를 사용하는 방법을 가르쳐주세요. 일반 자바 스크립트 AJAX (Jquery, DOJO 또는 그 이상)를 사용하고 있습니다.

답변

0

저는 this Post이 도움이 될 것 같아요. 그러나 대부분의 웹 서버에서는 요청에 SOAP 헤더 나 다른 이상한 것들이 필요하지 않으면 일반 HTTP Post (본문 요청에서 SOAP 형식없이)를 사용하여 웹 서비스를 호출 할 수 있습니다.

.NET 및 일반 자바 스크립트 예 :

.NET 웹 서비스

<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 

의 Web.config :

<webServices> 
    <protocols> 
     <add name="HttpSoap"/> 
     <add name="HttpPost"/> <!-- Allows plain HTTP Post --> 
     <add name="HttpSoap12"/> 
     <!-- Documentation enables the documentation/test pages --> 
     <add name="Documentation"/> 
    </protocols> 
</webServices> 

자바 스크립트 요청 :

function crearRequest(url) { 

    if (window.XMLHttpRequest) { 
     peticion_http = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject) { 
     peticion_http = new ActiveXObject('Microsoft.XMLHTTP'); 
    } 
    peticion_http.open('POST', url, true); //sync 
    peticion_http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    return peticion_http; 
} 

    peticion_http = crearRequest('http://localhost/wspuenteFirma/serviciopuente.asmx/ObtenerDocumentoOriginal'); 
    peticion_http.onreadystatechange = obtenerDocHandler; 
    var query_string = 'IdFirma=' + encodeURIComponent(docId); 
    peticion_http.setRequestHeader('Content-Length', query_string.length); 
    peticion_http.send(query_string); 

당신에게 이 요청을 보내라. 서버에 EST :

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> 

구문 분석을.

추신 : XML 대신 JSON 데이터를 보내고 받아들이도록 서버 및 브라우저 요청을 구성 할 수 있습니다.

도움이되기를 바랍니다.

+0

시간과 응답을 주셔서 감사합니다. 아직도 혼란 스럽습니다. (Java 관련 기술을 사용하고 있습니다.) SOAP 요청을 실제로 사용하고있는 AJAX 요청에 대해 알려주십시오. – Pawan

+0

그게 핵심입니다. 나는 SOAP 요청을 사용하지 않는다. 모든 SOAP 물건을 자바 스크립트에서 웹 서비스를 consumming 해요. SOAP을 사용하여 웹 서비스를 요청할 필요가 없다고 말하고 있습니다. 그냥 다른 제안을 제안. – jlvaquero

+0

어쨌든, 내 대답 맨 위에 링크를 확인 했습니까? 자바 스크립트에서 SOAP에 대해 알고 싶은 모든 것을 설명합니다. – jlvaquero

관련 문제