错误:访问被拒绝。使用.ajax()调用asmx Web服务时

时间:2013-08-07 08:28:28

标签: ajax json web-services sharepoint asmx

我刚刚为SharePoint 2013创建了一个新的Visual Studio 2012解决方案。我为SP2013和.asmx Web服务创建了一个应用程序。我想从我的应用程序中调用该Web服务,但我总是得到Error: Access is denied.

我的网络服务.cs代码:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class EmmaService : System.Web.Services.WebService
{

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string HelloWorld()
    {
        return "Hello World";
    } 
}

来自应用javascript的.ajax()来电:

$.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "http://localhost:59054/EmmaService.asmx/HelloWorld",
            dataType: "json",
            success: function(resp) {
                alert("success: " + resp);
            },
            error: function (xhr, ajaxOptions, thrownError) { 
                alert("error status: " + xhr.status);
                alert("error status text: " + xhr.statusText);
                alert("error response text: " + thrownError);
            },
        });

我看到人们在调用跨域Web服务时遇到同样的错误,但我的应用和服务位于同一个域,但我无法访问它,尽管我到处都有所有可能的权限(让我们说我是这台服务器上唯一的用户)。有人能帮助我吗?谢谢!

0 个答案:

没有答案