locked
SlideShow method error RRS feed

  • Question

  • User1510859543 posted

    I am trying to use the SlideShowExtender in toolkit and I get the following error.

    An unhandled exception occurred:

    Message: Unknown web method GetSlides.

    Parameter name: methodName

     

     Stack Trace:

       at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)

       at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)

       at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)

       at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

       at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)

       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    Below is my markup and webmethod 

                    <asp:Image ID="ImgSlide" runat="server" Height="300" Width="300" />
    
                    <ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server" 
                        TargetControlID="ImgSlide" 
                        SlideShowServiceMethod="GetSlides" 
                        SlideShowServicePath="~/WebServiceImages.asmx" 
                        AutoPlay="True" 
                        PlayInterval="1000" />
    
    Imports System.IO
    Imports AjaxControlToolkit
    Imports System.Web.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()>
    Public Class WebServiceImages
        Inherits System.Web.Services.WebService
    
        <WebMethod()>
        Public Shared Function GetSlides() As Slide()
            Dim slides As New List(Of Slide)()
            Dim sPath As String = HttpContext.Current.Server.MapPath("~/ketodocs/slides/")
            If sPath.EndsWith("\") Then
                sPath = sPath.Remove(sPath.Length - 1)
            End If
            Dim pathUri As New Uri(sPath, UriKind.Absolute)
            Dim files As String() = Directory.GetFiles(sPath)
            For Each file As String In files
                Dim filePathUri As New Uri(file, UriKind.Absolute)
                slides.Add(New Slide() With {
                  .Name = Path.GetFileNameWithoutExtension(file),
                  .Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                  .ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()
            })
            Next
            Return slides.ToArray()
        End Function
    
    End Class

    Friday, May 11, 2018 6:34 PM

Answers

  • User283571144 posted

    Hi dlchase,

    According to your codes, I found the image path you have set in the GetSlides web method is wrong.

    It will only return image file name to the client-side.

    I suggest you could try to add the image folder at the root of the application and use below codes:

    Webmethod:

        <WebMethod()>
        Public Function GetSlides() As AjaxControlToolkit.Slide()
            Dim slides As New List(Of Slide)()
            Dim sPath As String = HttpContext.Current.Server.MapPath("~/ketodocs/")
            If sPath.EndsWith("\") Then
                'sPath = sPath.Remove(sPath.Length - 1)
            End If
            sPath &= "slides\"
            'Dim pathUri As New Uri(sPath, UriKind.Absolute)
            Dim files As String() = Directory.GetFiles(sPath)
            For Each file As String In files
                'Dim filePathUri As New Uri(file, UriKind.Absolute)
                slides.Add(New Slide() With {
                  .Name = Path.GetFileNameWithoutExtension(file),
                  .Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                  .ImagePath = "ketodocs/slides/" + Path.GetFileName(file)
            })
            Next
            Return slides.ToArray()
    End Function
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 16, 2018 10:11 AM

All replies

  • User475983607 posted

    Removed "Shared" from the web method declaration.  ASMX uses instance methods unlike web method in an ASPX page.

    Friday, May 11, 2018 7:06 PM
  • User1510859543 posted

    That ALMOST worked.  The error went away but the image returned was placed after the </form> tag with style="display=none;"  when using using F12 developer tools.

    Can you see anything that would cause that?

    Friday, May 11, 2018 7:56 PM
  • User475983607 posted

    That ALMOST worked.  The error went away but the image returned was placed after the </form> tag with style="display=none;"  when using using F12 developer tools.

    Can you see anything that would cause that?

    No, that worked.  This is a different issue.

    Have you tried placing a breakpoint in the web method to verify the web method is operating as expected?  I would assume you have more than one image returned or should have more than one.  

    I can't see the markup so I have no idea if you have everything setup correctly.  I did a quick google and found these.

    https://www.experts-exchange.com/questions/25071859/AJAX-SlideShow.html

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=287

    Friday, May 11, 2018 8:23 PM
  • User1510859543 posted

    Below is my markup and it is pretty simple but still no images appear, only a box outline where the image should be.

        <form id="form1" runat="server">
    
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    
            <div id="slideshow" runat="server" class="row">
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 img-responsive">
    
                    <asp:Image ID="ImgSlide" runat="server" Height="300" Width="300" />
    
                    <ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server" 
                        TargetControlID="ImgSlide" 
                        SlideShowServiceMethod="GetSlides" 
                        SlideShowServicePath="~/WebServiceImages.asmx" 
                        AutoPlay="True" 
                        PlayInterval="1000" />
                </div>
            </div>
        </form>
    
    Below is web service code
    
    Imports System.IO
    Imports AjaxControlToolkit
    Imports System.Web.Services
    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()>
    Public Class WebServiceImages
        Inherits System.Web.Services.WebService
    
        <WebMethod()>
        Public Function GetSlides() As AjaxControlToolkit.Slide()
            Dim slides As New List(Of Slide)()
            Dim sPath As String = HttpContext.Current.Server.MapPath("~/ketodocs/")
            If sPath.EndsWith("\") Then
                'sPath = sPath.Remove(sPath.Length - 1)
            End If
            sPath &= "\slides"
            Dim pathUri As New Uri(sPath, UriKind.Absolute)
            Dim files As String() = Directory.GetFiles(sPath)
            For Each file As String In files
                Dim filePathUri As New Uri(file, UriKind.Absolute)
                slides.Add(New Slide() With {
                  .Name = Path.GetFileNameWithoutExtension(file),
                  .Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                  .ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()
            })
            Next
            Return slides.ToArray()
        End Function
    
    End Class

    Tuesday, May 15, 2018 2:25 PM
  • User1510859543 posted

    Also, this might help, the img tag results in a src=undefined.

    Tuesday, May 15, 2018 9:42 PM
  • User283571144 posted

    Hi dlchase,

    According to your codes, I found the image path you have set in the GetSlides web method is wrong.

    It will only return image file name to the client-side.

    I suggest you could try to add the image folder at the root of the application and use below codes:

    Webmethod:

        <WebMethod()>
        Public Function GetSlides() As AjaxControlToolkit.Slide()
            Dim slides As New List(Of Slide)()
            Dim sPath As String = HttpContext.Current.Server.MapPath("~/ketodocs/")
            If sPath.EndsWith("\") Then
                'sPath = sPath.Remove(sPath.Length - 1)
            End If
            sPath &= "slides\"
            'Dim pathUri As New Uri(sPath, UriKind.Absolute)
            Dim files As String() = Directory.GetFiles(sPath)
            For Each file As String In files
                'Dim filePathUri As New Uri(file, UriKind.Absolute)
                slides.Add(New Slide() With {
                  .Name = Path.GetFileNameWithoutExtension(file),
                  .Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                  .ImagePath = "ketodocs/slides/" + Path.GetFileName(file)
            })
            Next
            Return slides.ToArray()
    End Function
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 16, 2018 10:11 AM
  • User1510859543 posted

    Tried your code but still not getting images.  The hidden img tag (created by extender?) has a src=undefined rather than the path of src=ketodocs/slides/imagefile.jpg

    I am also trying to do this with just code-behind on page as below.  Also note that ketodocs is a virtual folder off the root.

    Imports System.IO
    Imports AjaxControlToolkit
    Imports System.Web.Services
    Imports System.Web.Script.Services
    Imports System.Collections.Generic
    
    Partial Class KetoStartNew
        Inherits System.Web.UI.Page
    
        <WebMethod()>
        Public Function GetSlides() As AjaxControlToolkit.Slide()
            Dim slides As New List(Of Slide)()
            Dim sPath As String = HttpContext.Current.Server.MapPath("~/ketodocs/")
            If sPath.EndsWith("\") Then
                'sPath = sPath.Remove(sPath.Length - 1)
            End If
            sPath &= "slides\"
            'Dim pathUri As New Uri(sPath, UriKind.Absolute)
            Dim files As String() = Directory.GetFiles(sPath)
            For Each file As String In files
                'Dim filePathUri As New Uri(file, UriKind.Absolute)
                slides.Add(New Slide() With {
                  .Name = Path.GetFileNameWithoutExtension(file),
                  .Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                  .ImagePath = "ketodocs/slides/" + Path.GetFileName(file)
            })
            Next
            Return slides.ToArray()
        End Function
    End Class

    And page (.aspx) markup as below.

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="KetoStartNew.aspx.vb" Inherits="KetoStartNew" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <div>
                <table>
                    <tr>
                        <td>
                            <asp:Image ID="Image1" runat="server" Height="300" Width="300" />
                            <cc1:SlideShowExtender ID="SlideShowExtender" runat="server" 
                                TargetControlID="Image1"
                                SlideShowServiceMethod="GetSlides" 
                                ImageTitleLabelID="lblImageTitle" 
                                ImageDescriptionLabelID="lblImageDescription"
                                AutoPlay="true" 
                                PlayInterval="2000" 
                                Loop="true">
                            </cc1:SlideShowExtender>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblImageTitle" runat="server" Text="Label"></asp:Label><br />
                            <asp:Label ID="lblImageDescription" runat="server" Text="Label"></asp:Label>
                        </td>
                    </tr>
                </table>
    
            </div>
        </form>
    </body>
    </html>

    Wednesday, May 16, 2018 1:44 PM
  • User1510859543 posted

    Nevermind...I fixed it from a typo. Thanks.

    Wednesday, May 16, 2018 2:27 PM