【问题标题】:How call soap service using jQuery如何使用jQuery调用soap服务
【发布时间】:2012-06-23 15:05:52
【问题描述】:

我在从 php 页面调用肥皂服务时遇到问题。我实现了两页,第一页是在 php 中创建的,第二页是在 asp.net 中创建的。在 asp.net 应用程序中,我有 SOAP 服务,应该从 php 调用哪些方法。

我的 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 应用程序。

当我点击在服务 i 浏览器控制台上调用 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.

【问题讨论】:

标签: asp.net jquery soap


【解决方案1】:

两件事:

1.) 这不再是 SOAP 服务,因为您来回传递 JSON

2.) 您遇到了名为Same Origin Policy的安全限制

Same Origin Policy 旨在防止恶意脚本调用恶意 Web 服务并将您的所有数据从浏览器发送给它们。基本上,您不能发出任何不使用 GET HTTP verb 的跨域请求(即与脚本起源不同的域)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多