2012-06-23 75 views
1

我從php頁面調用soap服務時遇到問題。我實現了兩頁,第一頁在php中創建,第二頁在asp.net中創建。在asp.net應用程序中,我有SOAP服務,應該從php調用哪些方法。在我的SOAP服務如何使用jQuery調用soap服務

方法,如下所示:

[WebMethod] 

[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 

public bool UpdateVotes(string vote) { 
      //Code 
} 

在PHP應用程序我呼籲UpdateVotes方法在下方式:

$.ajax({ 
       type: "POST", 
       url: "http://localhost:5690/VoteServices.asmx/UpdateVotes", 
       data: "{'vote': '" + vote + "'}", 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: function (msg) {     
       }, 
       error: function (xhr, status, error) {     
       } 
      }); 

首先我運行SOAP服務asp.net應用程序,並且比我開始php應用程序。

當我點擊鏈接調用Web方法服務,我的瀏覽器控制檯上我得到這個錯誤:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:5690/VoteServices.asmx/UpdateVotes 
XMLHttpRequest cannot load http://localhost:5690/VoteServices.asmx/UpdateVotes. Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin. 
+2

你谷歌的錯誤信息? – Gordon

+0

Access-Control-Allow-Origin不允許訪問http:// localhost:8080原因 - 您應該閱讀JSONP,CORS - http://stackoverflow.com/questions/3616440/cross-origin-resource-sharing -cors - 使用 - JSONP-和網絡工作人員 – Tisho

回答

1

兩件事情:

1)這不是一個SOAP服務不再因爲你來回傳遞JSON

2)你正在運行到一個安全限制稱爲Same Origin Policy

Same Origin Policy旨在防止惡意腳本與調用邪惡的Web服務,並從瀏覽器向他們發送的所有數據。基本上,您不能使用GET HTTP verb進行任何跨域請求(即與腳本不同的域)。