Accessing generic methods throug a proxy object

Discussion in 'ASP .Net Web Services' started by Ishan Bhalla, Aug 22, 2008.

  1. Ishan Bhalla

    Ishan Bhalla Guest

    Hello,

    I have a class defination for Location which can have multiple keywords. The
    keyword class has one Public property LocKeyword.

    For simplicity i have remove all the other properties.
    Public Class Loc
    Inherits basecore
    Private _keywords As List(Of LocKeyword)

    Public Property Keywords() As List(Of LocKeyword)
    Get
    Return _keywords
    End Get
    Set(ByVal value As List(Of LocKeyword))
    _keywords = value
    End Set
    End Property
    End Class

    Public Class LocKeyword
    Inherits BaseCore

    Public Keyword As String
    End Class


    Both Location and Keyword have their definations in the webservice project
    under App_GlobalResources


    The problem:
    When i try to create a proxy object of type Location in an ASP.Net website
    with the following code:

    Dim oLoc As New Loc

    oLoc.Keywords.Add(New LocKeyword())

    I get an error - the Add generic method does not come up. Is there any way i
    can make it? If i work on an object withen the Webservice project i dont
    have any problem - Ie the Code works.

    Any ideas?

    Regards
    Ishan
     
    Ishan Bhalla, Aug 22, 2008
    #1
    1. Advertising

  2. Ishan Bhalla

    Ishan Bhalla Guest

    Hello,

    I have a class definition for Location which can have multiple keywords. The
    LocKeyword class has one Public property LocKeyword.

    For simplicity i have remove all the other properties.
    Public Class Loc
    Inherits basecore
    Private _keywords As List(Of LocKeyword)

    Public Property Keywords() As List(Of LocKeyword)
    Get
    Return _keywords
    End Get
    Set(ByVal value As List(Of LocKeyword))
    _keywords = value
    End Set
    End Property
    End Class

    Public Class LocKeyword
    Inherits BaseCore

    Public Keyword As String
    End Class


    Both Location and Keyword have their definitions in the web service project
    under App_GlobalResources


    The problem:
    When i try to create a proxy object of type location in an ASP.Net website
    with the following code:

    Dim oLoc As New Loc

    oLoc.Keywords.Add(New LocKeyword())

    I get an error - the Add generic method does not come up. Is there any way i
    can make it? If i work on an object within the Webservice project i don’t
    have any problem - Ie the Code works.

    Any ideas?

    Regards
    Ishan
     
    Ishan Bhalla, Aug 22, 2008
    #2
    1. Advertising

  3. You haven't shown us your web methods. Do you ever return an instance of Loc
    from a web method? Only classes used as return values or parameter types in
    a web method will have proxy classes made for them. The following worked for
    me. Server: UsingGenerics.asmx.vb:
    -----------------------------------------------------------------------------------------------------------------------------
    Imports System.Web.Services
    Imports System.ComponentModel

    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
    _
    <ToolboxItem(False)> _
    Public Class UsingGenerics
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As Loc
    Dim lk As New List(Of LocKeyword)
    lk.Add(New LocKeyword With {.Keyword = "Key1"})
    lk.Add(New LocKeyword With {.Keyword = "key2"})
    Dim l As New Loc With {.Keywords = lk}
    Return l
    End Function

    End Class

    Public Class LocKeyword
    Private _keyword As String

    Public Property Keyword() As String
    Get
    Return _keyword
    End Get
    Set(ByVal value As String)
    _keyword = value
    End Set
    End Property

    End Class

    Public Class Loc
    Private _keywords As New List(Of LocKeyword)
    Public Property Keywords() As List(Of LocKeyword)
    Get
    Return _keywords
    End Get
    Set(ByVal value As List(Of LocKeyword))
    _keywords.Clear()
    _keywords.AddRange(value)
    End Set
    End Property
    End Class

    Public Class WillNotAppearOnClient
    Public Property DontCare() As Integer
    Get
    Return 1
    End Get
    Set(ByVal value As Integer)

    End Set
    End Property
    End Class
    -----------------------------------------------------------------------------------------------------------------------------
    Client: Module1.vb:

    Module Module1

    Sub Main()
    Using svc As New GenericService.UsingGenerics
    Dim list As GenericService.Loc = svc.HelloWorld()
    Console.WriteLine(list.Keywords(0).Keyword)
    ' Note GenericService.WillNotAppearOnClient will not
    End Using
    End Sub

    End Module
    -----------------------------------------------------------------------------------------------------------------------------
    I hope that helps

    --
    John Saunders | MVP - Connected System Developer

    "Ishan Bhalla" <> wrote in message
    news:...
    > Hello,
    >
    > I have a class defination for Location which can have multiple keywords.
    > The
    > keyword class has one Public property LocKeyword.
    >
    > For simplicity i have remove all the other properties.
    > Public Class Loc
    > Inherits basecore
    > Private _keywords As List(Of LocKeyword)
    >
    > Public Property Keywords() As List(Of LocKeyword)
    > Get
    > Return _keywords
    > End Get
    > Set(ByVal value As List(Of LocKeyword))
    > _keywords = value
    > End Set
    > End Property
    > End Class
    >
    > Public Class LocKeyword
    > Inherits BaseCore
    >
    > Public Keyword As String
    > End Class
    >
    >
    > Both Location and Keyword have their definations in the webservice project
    > under App_GlobalResources
    >
    >
    > The problem:
    > When i try to create a proxy object of type Location in an ASP.Net website
    > with the following code:
    >
    > Dim oLoc As New Loc
    >
    > oLoc.Keywords.Add(New LocKeyword())
    >
    > I get an error - the Add generic method does not come up. Is there any way
    > i
    > can make it? If i work on an object withen the Webservice project i
    > dont
    > have any problem - Ie the Code works.
    >
    > Any ideas?
    >
    > Regards
    > Ishan
    >
    >
     
    John Saunders, Aug 23, 2008
    #3
  4. Ishan Bhalla

    Ishan Bhalla Guest

    Hello John

    Thanks for the response, but it does solve my problem.

    I do not want to add a keyword in the webservice (HelloWorld()) - i want to
    add the keyword to the keyword collection in the front end ie - Your Sub
    Main()
    Something like this:

    Import <Webreference>

    Sub Main()
    Dim oLoc as Location

    oLoc.Keyword.Add(New LocKeyword With {.Keyword = "Key1"})
    oLoc.Keyword.Add(New LocKeyword With {.Keyword = "Key2"})

    End Sub

    End Module

    Well here is the background- i get the keyword information(and lots of other
    informaiton) from the webpage, so i want to assemble the location object in
    the webpages VB file.

    Regards
    Ishan

    "John Saunders" wrote:

    > You haven't shown us your web methods. Do you ever return an instance of Loc
    > from a web method? Only classes used as return values or parameter types in
    > a web method will have proxy classes made for them. The following worked for
    > me. Server: UsingGenerics.asmx.vb:
    > -----------------------------------------------------------------------------------------------------------------------------
    > Imports System.Web.Services
    > Imports System.ComponentModel
    >
    > <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    > <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
    > _
    > <ToolboxItem(False)> _
    > Public Class UsingGenerics
    > Inherits System.Web.Services.WebService
    >
    > <WebMethod()> _
    > Public Function HelloWorld() As Loc
    > Dim lk As New List(Of LocKeyword)
    > lk.Add(New LocKeyword With {.Keyword = "Key1"})
    > lk.Add(New LocKeyword With {.Keyword = "key2"})
    > Dim l As New Loc With {.Keywords = lk}
    > Return l
    > End Function
    >
    > End Class
    >
    > Public Class LocKeyword
    > Private _keyword As String
    >
    > Public Property Keyword() As String
    > Get
    > Return _keyword
    > End Get
    > Set(ByVal value As String)
    > _keyword = value
    > End Set
    > End Property
    >
    > End Class
    >
    > Public Class Loc
    > Private _keywords As New List(Of LocKeyword)
    > Public Property Keywords() As List(Of LocKeyword)
    > Get
    > Return _keywords
    > End Get
    > Set(ByVal value As List(Of LocKeyword))
    > _keywords.Clear()
    > _keywords.AddRange(value)
    > End Set
    > End Property
    > End Class
    >
    > Public Class WillNotAppearOnClient
    > Public Property DontCare() As Integer
    > Get
    > Return 1
    > End Get
    > Set(ByVal value As Integer)
    >
    > End Set
    > End Property
    > End Class
    > -----------------------------------------------------------------------------------------------------------------------------
    > Client: Module1.vb:
    >
    > Module Module1
    >
    > Sub Main()
    > Using svc As New GenericService.UsingGenerics
    > Dim list As GenericService.Loc = svc.HelloWorld()
    > Console.WriteLine(list.Keywords(0).Keyword)
    > ' Note GenericService.WillNotAppearOnClient will not
    > End Using
    > End Sub
    >
    > End Module
    > -----------------------------------------------------------------------------------------------------------------------------
    > I hope that helps
    >
    > --
    > John Saunders | MVP - Connected System Developer
    >
    > "Ishan Bhalla" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I have a class defination for Location which can have multiple keywords.
    > > The
    > > keyword class has one Public property LocKeyword.
    > >
    > > For simplicity i have remove all the other properties.
    > > Public Class Loc
    > > Inherits basecore
    > > Private _keywords As List(Of LocKeyword)
    > >
    > > Public Property Keywords() As List(Of LocKeyword)
    > > Get
    > > Return _keywords
    > > End Get
    > > Set(ByVal value As List(Of LocKeyword))
    > > _keywords = value
    > > End Set
    > > End Property
    > > End Class
    > >
    > > Public Class LocKeyword
    > > Inherits BaseCore
    > >
    > > Public Keyword As String
    > > End Class
    > >
    > >
    > > Both Location and Keyword have their definations in the webservice project
    > > under App_GlobalResources
    > >
    > >
    > > The problem:
    > > When i try to create a proxy object of type Location in an ASP.Net website
    > > with the following code:
    > >
    > > Dim oLoc As New Loc
    > >
    > > oLoc.Keywords.Add(New LocKeyword())
    > >
    > > I get an error - the Add generic method does not come up. Is there any way
    > > i
    > > can make it? If i work on an object withen the Webservice project i
    > > dont
    > > have any problem - Ie the Code works.
    > >
    > > Any ideas?
    > >
    > > Regards
    > > Ishan
    > >
    > >

    >
     
    Ishan Bhalla, Aug 25, 2008
    #4
  5. Ok, so what is the problem? Assemble oLoc and then send it to the web
    service.

    I still can't see your issue. Did you determine whether any of the web
    methods ever return or accept an instance of these classes?

    --
    John Saunders | MVP - Connected System Developer

    "Ishan Bhalla" <> wrote in message
    news:...
    > Hello John
    >
    > Thanks for the response, but it does solve my problem.
    >
    > I do not want to add a keyword in the webservice (HelloWorld()) - i want
    > to
    > add the keyword to the keyword collection in the front end ie - Your Sub
    > Main()
    > Something like this:
    >
    > Import <Webreference>
    >
    > Sub Main()
    > Dim oLoc as Location
    >
    > oLoc.Keyword.Add(New LocKeyword With {.Keyword = "Key1"})
    > oLoc.Keyword.Add(New LocKeyword With {.Keyword = "Key2"})
    >
    > End Sub
    >
    > End Module
    >
    > Well here is the background- i get the keyword information(and lots of
    > other
    > informaiton) from the webpage, so i want to assemble the location object
    > in
    > the webpages VB file.
    >
    > Regards
    > Ishan
    >
    > "John Saunders" wrote:
    >
    >> You haven't shown us your web methods. Do you ever return an instance of
    >> Loc
    >> from a web method? Only classes used as return values or parameter types
    >> in
    >> a web method will have proxy classes made for them. The following worked
    >> for
    >> me. Server: UsingGenerics.asmx.vb:
    >> -----------------------------------------------------------------------------------------------------------------------------
    >> Imports System.Web.Services
    >> Imports System.ComponentModel
    >>
    >> <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    >> <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
    >> _
    >> <ToolboxItem(False)> _
    >> Public Class UsingGenerics
    >> Inherits System.Web.Services.WebService
    >>
    >> <WebMethod()> _
    >> Public Function HelloWorld() As Loc
    >> Dim lk As New List(Of LocKeyword)
    >> lk.Add(New LocKeyword With {.Keyword = "Key1"})
    >> lk.Add(New LocKeyword With {.Keyword = "key2"})
    >> Dim l As New Loc With {.Keywords = lk}
    >> Return l
    >> End Function
    >>
    >> End Class
    >>
    >> Public Class LocKeyword
    >> Private _keyword As String
    >>
    >> Public Property Keyword() As String
    >> Get
    >> Return _keyword
    >> End Get
    >> Set(ByVal value As String)
    >> _keyword = value
    >> End Set
    >> End Property
    >>
    >> End Class
    >>
    >> Public Class Loc
    >> Private _keywords As New List(Of LocKeyword)
    >> Public Property Keywords() As List(Of LocKeyword)
    >> Get
    >> Return _keywords
    >> End Get
    >> Set(ByVal value As List(Of LocKeyword))
    >> _keywords.Clear()
    >> _keywords.AddRange(value)
    >> End Set
    >> End Property
    >> End Class
    >>
    >> Public Class WillNotAppearOnClient
    >> Public Property DontCare() As Integer
    >> Get
    >> Return 1
    >> End Get
    >> Set(ByVal value As Integer)
    >>
    >> End Set
    >> End Property
    >> End Class
    >> -----------------------------------------------------------------------------------------------------------------------------
    >> Client: Module1.vb:
    >>
    >> Module Module1
    >>
    >> Sub Main()
    >> Using svc As New GenericService.UsingGenerics
    >> Dim list As GenericService.Loc = svc.HelloWorld()
    >> Console.WriteLine(list.Keywords(0).Keyword)
    >> ' Note GenericService.WillNotAppearOnClient will not
    >> End Using
    >> End Sub
    >>
    >> End Module
    >> -----------------------------------------------------------------------------------------------------------------------------
    >> I hope that helps
    >>
    >> --
    >> John Saunders | MVP - Connected System Developer
    >>
    >> "Ishan Bhalla" <> wrote in message
    >> news:...
    >> > Hello,
    >> >
    >> > I have a class defination for Location which can have multiple
    >> > keywords.
    >> > The
    >> > keyword class has one Public property LocKeyword.
    >> >
    >> > For simplicity i have remove all the other properties.
    >> > Public Class Loc
    >> > Inherits basecore
    >> > Private _keywords As List(Of LocKeyword)
    >> >
    >> > Public Property Keywords() As List(Of LocKeyword)
    >> > Get
    >> > Return _keywords
    >> > End Get
    >> > Set(ByVal value As List(Of LocKeyword))
    >> > _keywords = value
    >> > End Set
    >> > End Property
    >> > End Class
    >> >
    >> > Public Class LocKeyword
    >> > Inherits BaseCore
    >> >
    >> > Public Keyword As String
    >> > End Class
    >> >
    >> >
    >> > Both Location and Keyword have their definations in the webservice
    >> > project
    >> > under App_GlobalResources
    >> >
    >> >
    >> > The problem:
    >> > When i try to create a proxy object of type Location in an ASP.Net
    >> > website
    >> > with the following code:
    >> >
    >> > Dim oLoc As New Loc
    >> >
    >> > oLoc.Keywords.Add(New LocKeyword())
    >> >
    >> > I get an error - the Add generic method does not come up. Is there any
    >> > way
    >> > i
    >> > can make it? If i work on an object withen the Webservice project i
    >> > dont
    >> > have any problem - Ie the Code works.
    >> >
    >> > Any ideas?
    >> >
    >> > Regards
    >> > Ishan
    >> >
    >> >

    >>
     
    John Saunders, Aug 26, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Murat Tasan
    Replies:
    1
    Views:
    8,073
    Chaitanya
    Feb 3, 2009
  2. Replies:
    3
    Views:
    625
    Malte Christensen
    Dec 30, 2005
  3. SagharAyyaz
    Replies:
    1
    Views:
    491
    Jonathan Mcdougall
    May 9, 2006
  4. D HANNEY
    Replies:
    3
    Views:
    460
    D HANNEY
    Jan 28, 2010
  5. Raj
    Replies:
    5
    Views:
    886
Loading...

Share This Page