Web Services and user defined types

Discussion in 'ASP .Net Web Services' started by Paolo Nunberg, Oct 2, 2004.

  1. 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



    *** 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
     
    Paolo Nunberg, Oct 2, 2004
    #1
    1. Advertising

  2. 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.


    --
    Ken Dopierala Jr.
    For great ASP.Net web hosting try:
    http://www.webhost4life.com/default.asp?refid=Spinlight
    If you sign up under me and need help, email me.

    "Paolo Nunberg" <> wrote in message
    news:3rB7d.28720$...
    > 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
    >
    >
    >
    > *** 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
    >
    >
     
    Ken Dopierala Jr., Oct 2, 2004
    #2
    1. Advertising

  3. 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!

    "Ken Dopierala Jr." <> ha scritto nel messaggio
    news:...
    > 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.
    >
    >
    > --
    > Ken Dopierala Jr.
    > For great ASP.Net web hosting try:
    > http://www.webhost4life.com/default.asp?refid=Spinlight
    > If you sign up under me and need help, email me.
    >
    > "Paolo Nunberg" <> wrote in message
    > news:3rB7d.28720$...
    > > 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
    > >
    > >
    > >
    > > *** 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
    > >
    > >

    >
    >
     
    Paolo Nunberg, Oct 3, 2004
    #3
    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. Guilherme Pinto
    Replies:
    1
    Views:
    324
    Victor Bazarov
    Oct 10, 2003
  2. Simon Morgan

    pointer arithmetic and user-defined types

    Simon Morgan, Aug 17, 2005, in forum: C Programming
    Replies:
    8
    Views:
    477
    lovecreatesbeauty
    Aug 18, 2005
  3. Oodini
    Replies:
    1
    Views:
    1,838
    Keith Thompson
    Sep 27, 2005
  4. wallge
    Replies:
    7
    Views:
    535
  5. Replies:
    1
    Views:
    539
    Sion Arrowsmith
    Jul 10, 2008
Loading...

Share This Page