5

ウィンドウ7のChromeブラウザを使用して、サーバーでホストされているSOAPサービスにアクセスしようとしています。私はSOAPUIで同じサービスとsoapアクションをテストし、応答を取得しました。また、Androidでもicesoapを使用してサーバーから正しい応答を取得しました。次に、Javaスクリプトで記述された次のコードを使用して、ブラウザーで応答を取得したいと考えています。同じ、それで私はさらに実装することができます、そしてそれは私に未定義のエラーを与えていますすなわちxmlHttp.status == 0

次のコードを使用して、ウィンドウデスクトップ(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 

URL「http://65.17.222.114/t2green/servicecontract/courses.svc」

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

リクエスト– </ p>

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

1 に答える 1

1

これは、Chrome によって適用される同一オリジン ポリシーが原因である可能性が最も高いです。これは、ローカル (file://) URL からリモート Web サービスへの要求を行うことができないことを意味します。

--allow-file-access-from-filesこの回答で概説されているように、Chrome を起動するときにコマンドライン フラグを使用してこの制限を削除します: https://stackoverflow.com/a/6083677/1972476

于 2013-01-24T12:18:39.477 に答える