简体   繁体   中英

ASPX page can't see namespace of my Web Service class

I'm writing my first web service class. I believe I've followed all of the directions from http://msdn.microsoft.com/en-us/library/bb398998.aspx , but the javascript fails because the namespace of the webservice is unknown.

My WebService:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using BusinessLogicLayer;

namespace AVWebService
{    
    [WebService(Namespace = "http://MyTestSite.Com/webservices/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]

    public class FillDropLists : System.Web.Services.WebService
    {

        [WebMethod]
        public Lookup[] GetRooms(string DataCenterId)
        {
            return BLL.getRooms(DataCenterId).ToArray();
        }
    }
}

My Web Config

  <system.web>
     <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/>      
        <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
     </httpHandlers>
  </system.web>

My ScriptManager is in my Master Page.

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="AVWebService.asmx" />
    </Services>
</asp:ScriptManager>

And finally, my javascript

function FillRoomsList(e) {
            var idx = e.selectedIndex;
            var dcId = e.options[idx].value;
            AVWebService.FillDropLists.GetRooms(dcId, OnRoomsReceived);
        }

The error I'm receiving, "AVWebService is undefined", would seem to indicate that the namespace isn't recognized at all.

You need to use ajax to integrate javascript with your web service. See the following link for an explanation on jQuery's implementation.

http://api.jquery.com/jQuery.ajax/

Example.

$.ajax({
     url : 'yourWebService.asmx',
     data: 'data you are sending to the web service'
     success: 'function to execute on success'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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