2013-01-24 13 views
5

Sto tentando di accedere al servizio SOAP ospitato nel server utilizzando il mio browser Chrome nella finestra 7. Ho testato lo stesso servizio e azione sapone in SOAPUI e ottenere risposta e anche in Android utilizzando icesoap e ottenere la risposta giusta dal server, Ora sto cercando di ottenere la risposta nel browser con il seguente codice scritto in java script per fare il stesso, in modo che io possa implementare ulteriormente, e mi sta dando errore non definito con iE xmlHttp.status == 0Richiesta SOAP JavaScript nel browser non dà risposta

Il seguente codice che ho usato e salvati come file HTML nella finestra del desktop (c:/Users/Vipin .sahu.OM/Desktop/Nuova cartella/soap.html) ed eseguirlo nel browser

<html> 
<head> 
    <title>SOAP JavaScript Client Test</title> 
    <script type="text/javascript"> 
     function soap() { 
     var xmlhttp = new XMLHttpRequest();    
     xmlhttp.open("POST", "http://65.17.222.114/t2green/servicecontract/Courses.svc?wsdl", true); 
     xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/ICourses/GetCountries"); 
     // build SOAP request 
     var sr ='<?xml version="1.0" encoding="utf-8"?>' + 
      '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">'+ 
      '<soapenv:Header/>'+ 
      '<soapenv:Body>'+ 
      '<tem:GetCountries>'+ 
      '</tem:GetCountries>'+ 
      '</soapenv:Body>'+ 
      '</soapenv:Envelope>'; 

     xmlhttp.onerror = function(e) { 
     alert("Error ocurred. Error = " + e.message); 
     } 

     xmlhttp.ontimeout = function(e) { 
     alert("Timeout error!"); 
     } 

     xmlhttp.onreadystatechange = function() { 
      if (xmlhttp.readyState == 4) { 
       if (xmlHttp.status == 200 || xmlHttp.status == 0) { 

       alert(xmlhttp.status); 

        } 
        else{ 
        alert(xmlhttp.status); 
        } 
       } 
       else{ 
       alert('error in response'); 
      } 

      } 

     xmlhttp.setRequestHeader("Content-Length", sr.length); 
     xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 

     xmlhttp.send(sr); 


     } 
</script> 
    <script type="text/javascript"> 
    function test(){   
    alert('ok alert is still working'); 
    } 
</script> 
</head> 
<body> 
     <form name="Demo" action="" method="post"> 
    <div> 
    <input type="button" value="Click Me" onclick="test()" />  
    <input type="button" value="Soap" onclick="soap()" /> 
    </div> 
    </form> 
    </body> 
    <html> 


Here are following url and action I used in android and getting requisite response 

URL "http://65.17.222.114/t2green/servicecontract/courses.svc"

Soap_action "http://tempuri.org/ICourses/GetCountries"

Richiesta -

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <tem:GetCountries/> 
    </soapenv:Body> 
    </soapenv:Envelope> 
+0

ha lavorato con la sessione Autenticazione sul IceSoap? (Seria per la domanda) –

risposta

1

Ciò è probabilmente dovuto alla stessa politica di origine applicata da Chrome. Ciò significa che non è possibile effettuare richieste da un URL locale (file: //) al servizio web remoto.

utilizzare il flag --allow-file-access-from-files riga di comando quando si avvia Chrome per rimuovere questa limitazione, come descritto in questa risposta: https://stackoverflow.com/a/6083677/1972476

+0

Se lo fai anche se non puoi garantire che i tuoi clienti lo stiano facendo. Sarebbe meglio chiamare il servizio dal tuo server e inviare la risposta al tuo javascript. –

+0

grazie .yup come posso testarlo allora .. c'è qualche server per quello. –

+0

Immagino che i client non abbiano solo un file locale come in questo scenario (di sviluppo). Dovrai ospitarlo usando un server web (Apache, lighttpd) dove l'URL corrisponde agli stessi vincoli della politica di origine per l'URL del servizio web (l'IP hard coded potrebbe essere un problema) –