I've created a scriptservice in my vb.net 4.0 web app (or web site... not sure which it is - does it matter?) because I want to call it from the client side. I get client errors saying my namespace is not recognized (HomepageService in the code below). I've tried qualifying it with the name configured on the project as "Root namespace", but the js says it doesn't recognize that namespace either.
The app is old - we recently converted it from dotnet 2.1 to 4.0.
I found the following related topic, because when I try to Import System.Web.Extensions in my HomepageServices.asmx.vb, visual studio says it doesn't recognize the thing even though i can see it, listed right there in studio under References.
[System.Web.Extensions Assembly cannot be resolved][1]
I tried posting a followup question to that topic, becauxse I tried following the instructions in the answer but they didn't work (I don't have a "Target Framework" in Project > Properties > Application), but someone deleted it because I guess i'm not allowed to ask followup questions?
I've consulted various sites and followed instructions, here's an example: http://www.asp.net/ajax/documentation/live/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx
Here is contents of HomepageService.asmx sitting in the root folder of my site:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Collections.Generic
<System.Web.Services.WebService(Namespace:="http://localhost/appname")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
<System.Web.Script.Services.ScriptService()> _
Public Class HomepageService
Inherits System.Web.Services.WebService
Shared _rand As Random = New Random(Environment.TickCount)
<WebMethod()> _
Public Function Test(ByVal s As String) As Integer
Return _rand.Next(0, 120)
End Function
End Class
Snippet from master page:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="Scriptmanager1" runat="server" EnablePageMethods="true">
<Scripts>
<asp:ScriptReference Path="CallWebServiceMethods.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="HomepageService.asmx" />
</Services>
</asp:ScriptManager>
and at the top of my page i import the js:
PageRequestManager.js:
HomepageService.set_defaultSucceededCallback(
OnLookupComplete);
HomepageService.set_defaultFailedCallback(
OnError);
function OnLookup() {
HomepageService.Test(stb.value);
}
function OnLookupComplete(result, userContext) {
// userContext contains symbol passed into method
var res = document.getElementById("_resultLabel");
res.innerHTML = userContext + " : <b>" + result + "</b>";
}
function OnError(result) {
alert("Error: " + result.get_message());
}
My web.config is a mess, but I'll be happy to post it...