Web Services and user defined types

P

Paolo Nunberg

Hi,

I am a newbie to Web Service and I cannot figure how to share a user defined
type between a Windows application and a Web Service.
I have a Windows Forms application and a Web Service, both referring to an
assembly which defines a simple structure (see code below).
When I try to compile the solution (VB.NET 2003) I get the following error
at the line marked 'Error here' in the code for 'Form1_Load':

Unable to connvert the type value "TestTipiWS.WSTipi.Persona" into
"Persone.Persona".

If I change the declaration of p into:

Dim p As WSTipi.Persona

the solution compiles and works as expected, but I would like to have a
single type definition.

Any suggestion?
Thanks!

------------------------------
Paolo Nunberg
(e-mail address removed)


*** Type definition assembly ***
Namespace Persone
Public Structure Persona
Dim ID As Integer
Dim Nome As String
End Structure
End Namespace

*** Form code ***
Imports Persone
....
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim Sv As New WSTipi.ServTipi
Dim p As Persona
p = Sv.GetPersona() '*** Error here ***
lbID.Text = p.ID
lbNome.Text = p.Nome
End Sub

*** Web Service ***
......
Imports Persone

<System.Web.Services.WebService(Namespace:="http://tempuri.org/ProvaWS/ServT
ipi"

)> _
Public Class ServTipi
Inherits System.Web.Services.WebService
......
<WebMethod()> _
Public Function GetPersona() As Persona
Dim p As Persona
p.ID = 11581
p.Nome = "Paolo Nunberg"
Return p
End Function

End Class
 
K

Ken Dopierala Jr.

Hi,

The easiest way to do this is to not have your Windows app refer to the user
defined type except through the web service. Just use it like you are using
it through the web service. That way you will only be referencing it in one
spot. When you change the UDT, recompile your web service, then update the
reference to it in your Windows app and you'll be able see the new
properties. You could also try using the CType function to see if that can
do it for you. I pass classes from web services to my ASP.Net app and CType
didn't work for me. But maybe using UDTs it will. If it does make sure you
have both apps pointing to the same DLL. If that gets messed up you'll be
wondering what the heck is going on because the compiler shows no problems
but the runtime version won't work. Good luck! Ken.
 
P

Paolo Nunberg

Hi Ken,

Ctype does not work for me either.
What baffles me is that in the 'Tracker' application from Infragistics
(www.infragistics.com) they apparently succeed in getting back their user
defined classes from a Web Service (see the Business Logic classes).

Thanks!
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top