从 JQuery 调用 Web 服务时出错

发布于 2024-08-29 07:27:12 字数 986 浏览 1 评论 0原文

当我尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏半生如梦愿梦如真 2024-09-05 07:27:12

通过将以下内容添加到网络配置中,最终解决了这个问题:

<webServices>
  <protocols>
    <add name="HttpPost"/>
  </protocols>
</webServices>

显然,服务器阻止了来自远程主机的传入请求。

Managed to finally solve this by adding the following to the web-config:

<webServices>
  <protocols>
    <add name="HttpPost"/>
  </protocols>
</webServices>

Appearently the server was blocking the incoming requests from a remote host.

眼前雾蒙蒙 2024-09-05 07:27:12

确保 web.config 文件配置正确。

Make sure web.config file is properly configured.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文