[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

Returning custom class from webservice and calling its methods

(Ian B)

1/21/2003 10:17:00 PM

I'm trying to work out how (and if it's even possible)
to return a custom class from a web service and
call a simple method of the returned custom class.

Is this possible and, if so, what am I doing wrong in this code?


Here's my web service: -
----------------------------------------------------------
Imports System.Web.Services

<WebService(Namespace:="MyTestServiceNamespace")> _
Public Class Service1
Inherits System.Web.Services.WebService
<WebMethod()> Public Function GimmeAClass1() As Class1
Return New Class1()
End Function

End Class
-----------------------------------------------------------


...and here's the class that is returned by the webmethod
in my web service: -
-----------------------------------------------------------
Imports System.Web.Services
Public Class Class1
<WebMethod()> Public Function GetAString() As String
Return "This is a string"
End Function
End Class
-----------------------------------------------------------


This is my test code which is in a windows application called
'Web_Service_Consumer_Test_Proj' that has a reference to the
webservice: -
-----------------------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles Button1.Click
Dim WS As New localhost.Service1()
Dim C1 As localhost.Class1
C1 = WS.GimmeAClass1
MsgBox(C1.GetAString)
End Sub
-----------------------------------------------------------

I am getting a class1 returned but when I try the code as above
I get a compiler error stating that 'GetAString' is not
a member of 'Web_Service_Consumer_Test_Proj.localhost.Class1'.
Is this just something I am doing wrong or am I trying to do the
impossible as far as a web service goes?

All help is very much appreciated!

Ian
2 Answers

Mike Andrews

1/20/2003 2:59:00 PM

0

I believe you don't want the <WebMethod()> attribute on your 'Public
Function GetAString() As String' declaration.

That's not necessary because the Web Service is the only one that needs
<WebMethod()> attributes on it's public, web service callable methods.

Later,
Mike

"Ian B" <i_best@hotmail.com> wrote in message
news:69c58cd1.0301190805.153b429d@posting.google.com...
> I'm trying to work out how (and if it's even possible)
> to return a custom class from a web service and
> call a simple method of the returned custom class.
>
> Is this possible and, if so, what am I doing wrong in this code?
>
>
> Here's my web service: -
> ----------------------------------------------------------
> Imports System.Web.Services
>
> <WebService(Namespace:="MyTestServiceNamespace")> _
> Public Class Service1
> Inherits System.Web.Services.WebService
> <WebMethod()> Public Function GimmeAClass1() As Class1
> Return New Class1()
> End Function
>
> End Class
> -----------------------------------------------------------
>
>
> ...and here's the class that is returned by the webmethod
> in my web service: -
> -----------------------------------------------------------
> Imports System.Web.Services
> Public Class Class1
> <WebMethod()> Public Function GetAString() As String
> Return "This is a string"
> End Function
> End Class
> -----------------------------------------------------------
>
>
> This is my test code which is in a windows application called
> 'Web_Service_Consumer_Test_Proj' that has a reference to the
> webservice: -
> -----------------------------------------------------------
> Private Sub Button1_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs)
> Handles Button1.Click
> Dim WS As New localhost.Service1()
> Dim C1 As localhost.Class1
> C1 = WS.GimmeAClass1
> MsgBox(C1.GetAString)
> End Sub
> -----------------------------------------------------------
>
> I am getting a class1 returned but when I try the code as above
> I get a compiler error stating that 'GetAString' is not
> a member of 'Web_Service_Consumer_Test_Proj.localhost.Class1'.
> Is this just something I am doing wrong or am I trying to do the
> impossible as far as a web service goes?
>
> All help is very much appreciated!
>
> Ian


(Ian B)

1/24/2003 10:19:00 AM

0

Thanks for the reply, Mike.

I think I had tried it with and without the <WebMethod()> attribute
but, just in case, I tried your suggestion but with no luck!

The only option offered by the intellisense is GetType and I'm getting
the same error as before: 'GetAString' is not a member of
'Web_Service_Consumer_Test_Proj.localhost.Class1'.

Any other ideas?


"Mike Andrews" <mikea@farpointer.net> wrote in message news:<edskuuIwCHA.1620@TK2MSFTNGP11>...
> I believe you don't want the <WebMethod()> attribute on your 'Public
> Function GetAString() As String' declaration.
>
> That's not necessary because the Web Service is the only one that needs
> <WebMethod()> attributes on it's public, web service callable methods.
>
> Later,
> Mike
>
> "Ian B" <i_best@hotmail.com> wrote in message
> news:69c58cd1.0301190805.153b429d@posting.google.com...
> > I'm trying to work out how (and if it's even possible)
> > to return a custom class from a web service and
> > call a simple method of the returned custom class.
> >
> > Is this possible and, if so, what am I doing wrong in this code?
> >
> >
> > Here's my web service: -
> > ----------------------------------------------------------
> > Imports System.Web.Services
> >
> > <WebService(Namespace:="MyTestServiceNamespace")> _
> > Public Class Service1
> > Inherits System.Web.Services.WebService
> > <WebMethod()> Public Function GimmeAClass1() As Class1
> > Return New Class1()
> > End Function
> >
> > End Class
> > -----------------------------------------------------------
> >
> >
> > ...and here's the class that is returned by the webmethod
> > in my web service: -
> > -----------------------------------------------------------
> > Imports System.Web.Services
> > Public Class Class1
> > <WebMethod()> Public Function GetAString() As String
> > Return "This is a string"
> > End Function
> > End Class
> > -----------------------------------------------------------
> >
> >
> > This is my test code which is in a windows application called
> > 'Web_Service_Consumer_Test_Proj' that has a reference to the
> > webservice: -
> > -----------------------------------------------------------
> > Private Sub Button1_Click(ByVal sender As System.Object,
> > ByVal e As System.EventArgs)
> > Handles Button1.Click
> > Dim WS As New localhost.Service1()
> > Dim C1 As localhost.Class1
> > C1 = WS.GimmeAClass1
> > MsgBox(C1.GetAString)
> > End Sub
> > -----------------------------------------------------------
> >
> > I am getting a class1 returned but when I try the code as above
> > I get a compiler error stating that 'GetAString' is not
> > a member of 'Web_Service_Consumer_Test_Proj.localhost.Class1'.
> > Is this just something I am doing wrong or am I trying to do the
> > impossible as far as a web service goes?
> >
> > All help is very much appreciated!
> >
> > Ian