浏览器中的SOAP请求JavaScript未给出响应

浏览器中的SOAP请求JavaScript未给出响应,javascript,web-services,soap,xmlhttprequest,request,Javascript,Web Services,Soap,Xmlhttprequest,Request,我正在尝试使用Windows7中的Chrome浏览器访问服务器中托管的SOAP服务。我已经在SOAPUI中测试了相同的服务和soap操作,并获得了响应,在android中也使用了icesoap并从服务器获得了正确的响应,现在我希望在浏览器中获得响应,并使用java脚本编写以下代码来做同样的事情,以便我可以进一步实现,它给出了ie xmlHttp.status==0的未定义错误 以下代码是我在WindowDesktop(c:/Users/vipin.sahu.OM/desktop/New fold

我正在尝试使用Windows7中的Chrome浏览器访问服务器中托管的SOAP服务。我已经在SOAPUI中测试了相同的服务和soap操作,并获得了响应,在android中也使用了icesoap并从服务器获得了正确的响应,现在我希望在浏览器中获得响应,并使用java脚本编写以下代码来做同样的事情,以便我可以进一步实现,它给出了ie xmlHttp.status==0的未定义错误

以下代码是我在WindowDesktop(c:/Users/vipin.sahu.OM/desktop/New folder/soap.HTML)中使用并保存为HTML文件的,并将其运行到浏览器中

<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 

soapjavascript客户端测试
函数soap(){
var xmlhttp=new XMLHttpRequest();
open(“POST”http://65.17.222.114/t2green/servicecontract/Courses.svc?wsdl“,对);
setRequestHeader(“SOAPAction”http://tempuri.org/ICourses/GetCountries");
//生成SOAP请求
var sr=''+
''+
''+
''+
''+
''+
''+
'';
xmlhttp.onerror=函数(e){
警报(“出现错误。错误=“+e.message”);
}
xmlhttp.ontimeout=函数(e){
警报(“超时错误!”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4){
if(xmlHttp.status==200 | | xmlHttp.status==0){
警报(xmlhttp.status);
}
否则{
警报(xmlhttp.status);
}
}   
否则{
警报(“响应错误”);
}
} 
setRequestHeader(“内容长度”,sr.Length);
setRequestHeader(“内容类型”,“text/xml;charset=utf-8”);
xmlhttp.send(sr);
}
函数测试(){
警报(“正常警报仍在工作”);
}
下面是我在android中使用的url和操作,并得到了必要的响应
URL“http://65.17.222.114/t2green/servicecontract/courses.svc"

Soap\u操作“http://tempuri.org/ICourses/GetCountries"

请求——

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

这很可能是因为Chrome应用了相同的原产地政策。 这意味着您无法从本地(文件://)URL向远程web服务发出请求


启动Chrome时,请使用
--允许从文件访问文件
命令行标志来删除此限制,如回答中所述:

如果您这样做,尽管您无法确保您的客户端正在这样做。最好从您的服务器调用该服务并将响应发送回javascript。谢谢。是的,那么我如何测试它。。我想客户端不会像这个(开发)场景中那样只有一个本地文件。您必须使用web服务器(Apache、lighttpd)托管它,其中URL与web服务URL的同源策略约束相匹配(硬编码的IP可能是一个问题)。您是否在IceSoap上使用了会话身份验证?(很抱歉提出这个问题)