正在学习通过ScriptManager,客户端调用WebService方法,按照网上写的代码。使用的时候点击button,没有任何显示,在浏览器左下脚显示网页上有错误!!
哪位高手帮忙下,代码如下:
客户端:
<asp:ScriptManager ID="ScriptManager1" runat="server" >
   <Services>
       <asp:ServiceReference Path="http://localhost:81/a/Service.asmx"  />
   </Services>
  </asp:ScriptManager>
<input id="Button1" type="button" value="点击调用WebService" onclick="button_click()"  /><br /><script type="text/javascript" language="JavaScript">
  function button_click()
  {
    requestSimpleService = service.HelloWorld(
    OnRequestComplete    //完成事件
   );
    return false;
   }
        
  function OnRequestComplete(result) 
  {
   alert(result);
  }
</script>服务器端:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService] public class Service : System.Web.Services.WebService
  {       [WebMethod]
       public string HelloWorld()
       {
           return "Hello World";
       }
       
    }

解决方案 »

  1.   

    http://www.cnblogs.com/teracy/archive/2007/09/07/885635.html
      

  2.   

    你的aspx页面不全,ScriptManager有引用WebService么?如
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
    <asp:ServiceReference Path="http://localhost/AJAXWebServiceDemo/WebServiceDemo.asmx" />
    </Services>
    </asp:ScriptManager>
      

  3.   

    就是看着他写的。 唯一的区别是,他的PATH是调用同一个项目里的WebService,我的是调用了发布好的
    <asp:ServiceReference Path="http://localhost:81/a/Service.asmx"  /> 
      

  4.   

    <asp:ServiceReference Path="http://localhost:81/a/Service.asmx"  /> 
    =>
    <asp:ServiceReference Path="~/Service.asmx"  /> ...requestSimpleService = service.HelloWorld( 
    =>
    requestSimpleService = Service.HelloWorld( 
      

  5.   


    有引用的阿<asp:ServiceReference Path="http://localhost:81/a/Service.asmx"  /> 
      

  6.   

    http://localhost:81/a/Service.asmx
    这个路径是指明你在本地的IIS有个端口为81的,虚拟目录为a里的Service.asmx。如果Service.asmx是项目里的话,改成"~/Service.asmx"吧。
      

  7.   


    改成大写的Service.HelloWorld()还是没用,Path="http://localhost:81/a/Service.asmx"  />是我发布的地址,你介意的Path="~/Service.asmx"是文件夹上一层的,Service.asmx没在上一层文件夹
      

  8.   

    是的,我把WebService放在了端口为81的,虚拟目录为a里,没在项目里。实际用的时候WebService不可能在都一个文件夹里的
      

  9.   

    我把WebService放到同一个项目文件夹就可以正常调用了能成功显示HelloWord,那就是我的Path写错了,谁能告诉我下,应该怎么写?
      

  10.   

    我把WebService放到同一个项目文件夹,<asp:ServiceReference Path="Service.asmx"  /> 就可以正常调用了能成功显示HelloWord,那就是我的Path写错了,谁能告诉我下,应该怎么写?才能调用在其他路径的WebService
      

  11.   

    难道是我写成81端口出现的问题,正常是80端口,但是80端口我的IIS就不能用了
      

  12.   

    才能调用在其他路径的WebService
    ==
    你的这个webservice有设置为虚拟目录么?
      

  13.   

    当然设置过虚拟目录了,直接在网页上打http://localhost:81/a/Service.asmx,是可以调用的。
      

  14.   

    可否调用外部的Web Service?
    1、该Web Service必须也是ASP.NET建立的,且必须标示为ScriptService;
    2、受限于XMLHttpRequest不允许跨网域调用的限制,使用者必须调整游览器的安全设定所以最好的方式是自己建一个Web Service,在此Web Service中串接外部的Web Service,这样不公可以调用非ASP.NET所建立的WEb Service,而且不受XMLHttpRequest不能跨网域的限制?书的抄来的。
      

  15.   

    串接方式就是“添加Web引用”->“本地计算机上的Web服务”->定位到http://localhost:81/a/Service.asmx。在自己的项目里再建一个WebService,
    [WebMethod]
    public string HelloWorld() {
            localhost.WebService ws = new localhost.WebService();
            return ws.HelloWorld(); //调用81端口里的那个
    }然后,就不用说了吧?
      

  16.   

    service.HelloWorld名称空间要正确,大小写要注意,还有Web
    服务的方法签名也要正确。