0

This is my AJAX Application where i need to contact my Webservice running in server .

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

This is the SOAP Request which i picked up from the SOAP UI , which was working fine

<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>

Please tell me how can i use use this SOAP XML message within the sendRequest function . I am using only plain Java Script AJAX ( Nothing like Jquery , DOJO , or any )

Pawan
  • 31,545
  • 102
  • 256
  • 434

1 Answers1

0

I think this Post can help you. But most of web servers allows you to invoke webservices using plain HTTP Post (without SOAP format in the body request) if the request doesn't need SOAP headers or other weird things.

An example in .NET and plain javaScript:

.NET web service

<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>

JavaScript request:

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);

You send this request to the server:

POST /wsGestorFirmaExterno/GestorFirmaExterno.asmx/ObtenerDocumentoOriginal HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length

idFirma=string

and recive this response from the server:

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>

Parse it with javascript to obtain the info you need.

PS: You can configure the server and the browser request to send and recive JSON data instead of XML.

I hope it's helps.

Community
  • 1
  • 1
jlvaquero
  • 8,571
  • 1
  • 29
  • 45
  • Thanks for your time and response , still i am confused ( I am into Java related technology ) and could you please tell me with in the AJAX request where you are actually using the SOAP Request ?? – Pawan Dec 15 '11 at 10:57
  • That's the point. I'm not usign SOAP request. I'm consumming a web service in javascript without all the SOAP stuff. I'm just telling you that maybe you don't need to use SOAP to request a webservice. Just suggesting a diferent aproach. – jlvaquero Dec 15 '11 at 12:04
  • Anyway, did you check the link at the top of my answer? It explains all that you want to know about SOAP in javascript. – jlvaquero Dec 15 '11 at 12:13