troubleshooting Question

web service error undefined.

Avatar of reginab
reginab asked on
AJAX
8 Comments1 Solution1232 ViewsLast Modified:
Hi, I keep getting an error of 'setDates' is undefined, when I try to call to my webservice webmethod.  I have everything defined properly in my scriptmanager tag, and in my .vb for my webservice.  I am confident in my javascript as well. I using VS2008 and I am wondering if anyone else has seen this issue.  I have also tried not adding the web reference to the project and also adding it conventially as one would to call the web service in a more conventional way from code, not from ajax.  I think at this point I am missing something really small.
this is setDates.vb
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
'added
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Web.Script.Services
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
'<WebService(Namespace:="http://tempuri.org/")> _
'<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
'<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
'the lines above here were added automatically and as far as I can tell make the service not accessible from the client
'I added the following line because I know it works that way.
<ScriptService(), WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class setDates
    Inherits System.Web.Services.WebService
 
   
 
    <WebMethod()> _
    Public Function setFromYear(ByVal this As Boolean, ByVal forQtr As Boolean) As String
        Dim result As String
 
        If this Then
            Today = Now
            If forQtr Then
                result = "1" & "/" & "1" & "/" & Today.Year.ToString
                'dtToQ = "12" & "/" & "31" & "/" & Today.Year.ToString
            Else
                result = "1" & "/" & "1" & "/" & Today.Year.ToString
                'dtTo = "12" & "/" & "31" & "/" & Today.Year.ToString
            End If
        Else
            Dim getYear As Long
            Today = Now
            getYear = Today.Year - 1
            If forQtr Then
                result = "1" & "/" & "1" & "/" & getYear.ToString
                'dtToQ = "12" & "/" & "31" & "/" & getYear.ToString
            Else
                result = "1" & "/" & "1" & "/" & getYear.ToString
                'dtTo = "12" & "/" & "31" & "/" & getYear.ToString
            End If
        End If
        Return result
    End Function
End Class
********************************************************************************
this is from the aspx page:
function Button1_onclick() {
        Sys.Debug.trace("start = ");
        Sys.Debug.trace("count = ");
        ret = setDates.setFromYear(0, 0, OnComplete, OnTimeOut, OnError);
        //Sys.Debug.trace(ret);
        //document.getElementById('Date5').innerText = ret;
        return(true);
 
        }
 
        function OnComplete(args) {
        alert(" and here");
        document.getElementById('Date5').innerText = args;
        }
 
        function OnTimeOut(args) {
        alert("Service call timed out.");
 
        }
 
        function OnError(args) {
        alert("Error calling service method.");
        }
 
 
<asp:ScriptManager ID="ScriptManager1" runat="server" >
            <Services>
                <asp:ServiceReference Path="setDates.asmx" />
            </Services>
        </asp:ScriptManager>
&nbsp;<asp:LinkButton ID="lastYear" runat="server" Width="96" CssClass="MyLinkButton"
                                        Text="Last Year" OnClientClick="Button1_onclick();return false;"></asp:LinkButton>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros