2014-04-01 40 views
0

我試圖使用soap作爲後端服務併爲我的應用程序提供數據。僅在JavaScript中實現肥皂環境

我的問題是,如果我們只使用JavaScript框架(例如:灰燼,角),而服務器端語言(例如:PHP)

這有可能實現嗎?

非常感謝!

+0

是的,我已經做了webDAV回來的一天。你只需要模板化一些Ajax響應,並清除你的XML DOM技能。 – dandavis

回答

1

如果不使用任何服務器端語言,則無法使用javascript框架創建SOAP服務。它只能從Java腳本訪問SOAP WSDL。 這裏舉的例子:

<script type="text/javascript"> 
    function soap() { 
     var xmlhttp = new XMLHttpRequest(); 
     xmlhttp.open('POST', 'https://testSoapURL.com/', true); 

     // build SOAP request 
     var service = 
      '<?xml version="1.0" encoding="utf-8"?>' + 
      '<soapenv:Envelope ' + 
       'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + 
       'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ' + 
       'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' + 
       'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' + 
       '<soapenv:Body>' + 
       '<api:some_api_callsoapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' + 
         '<username xsi:type="xsd:string">login_uName</username>' + 
         '<password xsi:type="xsd:string">pass</password>' + 
        '</api:some_api_call>' + 
       '</soapenv:Body>' + 
      '</soapenv:Envelope>'; 

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

        alert('done check the response'); 
       } 
      } 
     } 
     // Send the POST request 
     xmlhttp.setRequestHeader('Content-Type', 'text/xml'); 
     xmlhttp.send(service); 
     //Now send the request   
    } 
</script>