Logo

解决Asp.Net下访问WebService爆出权限错误

photo
Pastore Antonio

2017年03月17日

很多时候我们在建立Asp.net的Web服务的时候会采用WebService来建立,一般情况下其实是没有什么问题的,但是如果将这个服务直接去用前端的Ajax去调用的时候便会有一些问题。

一般情况下我们会用如下的代码去调用我们的WebService:

function callSvc() {
    $.ajax({
        type: "POST",
        url: "Service1.asmx/HelloWorld",
        data: "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(data, status) { alert(data); },
        error: function(request, status, error) { alert(request); alert(status); alert(error); }
    });
}

这个时候会报错!

报错信息应该差不多和下面的语句一样:

“Only Web services with a [ScriptService] attribute on the class definition can be called from script.”

这种情况下,我们要稍微修改下我们的WebService:

[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService

这样就差不多啦。下面提供两个链接快速的用来测试下支不支持Js。

https://<URL>/SimpleWebService.asmx/js
https:///SimpleWebService.asmx/jsdebug

本文为原创文章,请注意保留出处!

留言板

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

修复群晖Synology Drive client右键菜单缺失问题 Local, clean & environmental 作者:Pastore Antonio
1806 浏览量
1779 浏览量
configure: error: Package requirements (oniguruma) were not met Local, clean & environmental 作者:Pastore Antonio
1524 浏览量
Adobe Acrobat Pro 激活 Local, clean & environmental 作者:Pastore Antonio
1519 浏览量
追寻日出,找回自己 Local, clean & environmental 作者:Pastore Antonio
1488 浏览量