Accessing generic methods throug a proxy object

I

Ishan Bhalla

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
 
I

Ishan Bhalla

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
 
J

John Saunders

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

Ishan Bhalla

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
 
J

John Saunders

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top