简体   繁体   English

来自AJAX的Web服务调用,未找到服务

[英]Web Service call from AJAX, service not found

I have a web method that gets kicked off with an AJAX call here is my web method: 我有一个Web方法,该方法通过AJAX调用开始,这是我的Web方法:

 [WebMethod(EnableSession=true)]
 public void ProcessAddress(Dictionary<string, string> Header, bool AddrValues)
 {

    _service.ProcessNoMatchModal(Header, AddrValues);
 }

which is called from this: 从这个调用:

 $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "../Services/Address.asmx/ProcessAddress",
        data: JSON.stringify(data),
        dataType: "json",
        success: function(data) {
            alert("success");
        },
        error: function() { 
            alert("error");
        },
        complete: function() { },
        asynch: false
    });

What is more confusing is I have two virtual directories that are pointing to the same code source and for the first this service works and is available but for the second it does not work and I see a 404 in firebug 更令人困惑的是,我有两个指向相同代码源的虚拟目录,对于第一个,此服务有效并且可用,但是对于第二个它却不起作用,并且我在Firebug中看到404

Any leads/suggestions would be helpful 任何线索/建议都将有所帮助

From Here: 从这里:

  1. The method MUST be static 该方法必须是静态的
  2. The method needs to be decorated with [WebMethod()] 该方法需要用[WebMethod()]装饰
  3. The method needs to be decorated with [ScriptMethod()] if you want to make a ASP.NET AJAX callback to it 如果要对该方法进行ASP.NET AJAX回调,则需要用[ScriptMethod()]装饰该方法。

Since it's an 404 http error I would blame the relative path reference you've made (with the double dot) in the url setting. 由于这是一个404 http错误,我将怪罪您在url设置中使用双点引起的相对路径引用。

From your first location you call the webservice with the correct path, from the second you are targeting a wrong path... Try looking at the actual path you are calling using Fiddler or Chrome Developer Tools to see if I'm correct. 从第一个位置使用正确的路径调用Web服务,从第二个位置定位错误的路径...尝试使用Fiddler或Chrome开发者工具查看您正在调用的实际路径,以查看我是否正确。

If you call this function from virtual directories with different depths you would probably be better off without a relative path reference but start at the root.. One of the following should work I guess: 如果您从具有不同深度的虚拟目录中调用此函数,则最好是在没有相对路径引用的情况下,而是从根目录开始。.我猜应该是以下之一:

url: "Services/Address.asmx/ProcessAddress"
url: document.location.hostname + "/Services/Address.asmx/ProcessAddress"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM