从 JQuery 调用 Web 服务时出错
当我尝试从 Jquery 调用简单的 Web 服务方法时,遇到一个奇怪的问题。
在本地它工作正常,但在我的测试服务器上却不行。
jquery 请求看起来像这样(只显示实际请求,而不显示方法的其余部分):
$.ajax({
type: "POST",
url: "/Service/Service.asmx/AddTab",
data: "tab=" + element.innerHTML,
success: function(msg) {
alert('success');
}
});
当我从测试服务器本地运行它时,它工作正常,这让我想知道它是否可能是我错过的一些设置在 IIS 中。
如果导航到 .asmx 文件并单击 AddTab 方法,我将获得 SOAP 1.1 和 SOAP 1.2 XML 的列表,但不会获得 HTTP POST 请求。如果我在本地导航到它,我会得到所有三个(SOAP 1.1、SOAP 1.2 和 HTTP Post)
该服务设置如下:
[WebService(Namespace = "mynamespace")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService()]
public class Service : System.Web.Services.WebService
{
[WebMethod(EnableSession=true)]
[ScriptMethod()]
public void AddTab(string tab)
{
//Some code to add a tab which evidently works locally...
}
}
有人知道我在这里缺少什么吗?
I have a strange problem when I'm trying to call a simple webservice method from Jquery.
Locally it works fine, but on my test-server it does not.
The jquery request looks like this (only showing the actual request and not the rest of the method):
$.ajax({
type: "POST",
url: "/Service/Service.asmx/AddTab",
data: "tab=" + element.innerHTML,
success: function(msg) {
alert('success');
}
});
When I run this locally from the test-server it works fine, which has me wondering if it could be some setting that I've missed in the IIS.
If I navigate to the .asmx file and click the AddTab method I get a list of SOAP 1.1 and SOAP 1.2 XML, but not the HTTP POST request. If I navigate to it locally I get all three (SOAP 1.1, SOAP 1.2 and HTTP Post)
The service is set up as follows:
[WebService(Namespace = "mynamespace")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService()]
public class Service : System.Web.Services.WebService
{
[WebMethod(EnableSession=true)]
[ScriptMethod()]
public void AddTab(string tab)
{
//Some code to add a tab which evidently works locally...
}
}
Anyone have a clue what I'm missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过将以下内容添加到网络配置中,最终解决了这个问题:
显然,服务器阻止了来自远程主机的传入请求。
Managed to finally solve this by adding the following to the web-config:
Appearently the server was blocking the incoming requests from a remote host.
确保 web.config 文件配置正确。
Make sure web.config file is properly configured.