473,320 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Web Services and user defined types

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
pa***********@tin.it
*** 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

Nov 21 '05 #1
2 4002

When you create a Web Reference in a Web Service consumer application, you
don't get the original type returned by the Web Service but a "flat" copy of
the type. The copy contains all public properties of the original type but
no methods. This copy is defined along with the auto-generated proxy class
in reference.cs (or reference.vb if you are using Visual Basic) file.

The underlying reason why it works this way is that with Web Services, you
are supposed to share schema and contract, but not implementation (for more
background, read e.g.,
http://msdn.microsoft.com/msdnmag/is...o/default.aspx)

That said, it is possible to share types between a Web Service and its
consumer. Simply remove the flat type definition from reference.cs and add a
'using NamespaceThatContainsYourCustomType'. For an example, see
http://objectsharp.com/Blogs/bruce/a...05/23/499.aspx.

Note that if you do share types this way, you are giving away some of the
benefits of loose coupling. It can lead to the very same type versioning
problems that Web Services try to avoid in the first place. Also the SOA
police (not me) would say that you are breaking one of the SOA tenets by
sharing a type.

Note also that modifying auto-generated proxies is in general a bad idea
because you will lose the changes every time you regenerate the proxy.

Regards,
Sami

"Paolo Nunberg" <pa***********@tin.it> wrote in message
news:4L********************@news4.tin.it...
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
pa***********@tin.it
*** 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

Nov 21 '05 #2
Hi Sami,
your answer was most helpful.
Thanks!
"Sami Vaaraniemi" <sa**********@pleasejippii.fi> ha scritto nel messaggio
news:uL**************@TK2MSFTNGP09.phx.gbl...

When you create a Web Reference in a Web Service consumer application, you
don't get the original type returned by the Web Service but a "flat" copy of the type. The copy contains all public properties of the original type but
no methods. This copy is defined along with the auto-generated proxy class
in reference.cs (or reference.vb if you are using Visual Basic) file.

The underlying reason why it works this way is that with Web Services, you
are supposed to share schema and contract, but not implementation (for more background, read e.g.,
http://msdn.microsoft.com/msdnmag/is...o/default.aspx)

That said, it is possible to share types between a Web Service and its
consumer. Simply remove the flat type definition from reference.cs and add a 'using NamespaceThatContainsYourCustomType'. For an example, see
http://objectsharp.com/Blogs/bruce/a...05/23/499.aspx.

Note that if you do share types this way, you are giving away some of the
benefits of loose coupling. It can lead to the very same type versioning
problems that Web Services try to avoid in the first place. Also the SOA
police (not me) would say that you are breaking one of the SOA tenets by
sharing a type.

Note also that modifying auto-generated proxies is in general a bad idea
because you will lose the changes every time you regenerate the proxy.

Regards,
Sami

"Paolo Nunberg" <pa***********@tin.it> wrote in message
news:4L********************@news4.tin.it...
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
pa***********@tin.it
*** 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


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Guilherme Pinto | last post by:
Hello. I am reading the book written by Bjarne Stroustrup called " The C++ Programming Language - Special Edition" and had a doubt which a think is really important to distinguish between the...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
0
by: summer cwj via .NET 247 | last post by:
hi all, I want to parse the wsdl file . It is ease to parse the parts of wsdl except that the part of types. Because I don't know how to use the System.Web.Services.Description member types . I...
2
by: John Wilson | last post by:
I have an application that can access data both locally and through web services (it may be working in a disconnected mode). I have defined my data objects (e.g. ObjectA) in a separate component...
1
by: Paolo Nunberg | last post by:
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...
2
by: Les Stockton | last post by:
In VB6 you had a Type and End Type to define your own data types. Are the only ways to do this in VB.Net with enums, struct and class. How's the best way to define user defined types?
6
by: Moshe Kravchik | last post by:
Hi all! I have 2 web services, one writtenin C++ (ATL) and another one in C#. Is there a way to define data stuctures in a single place both services could use? The structures are the same, but if...
0
by: Alex | last post by:
I have a web service in which I declare a user defined object. One of the properties, I declare it and default it's value as follows: private DateTime _callbackTime =...
4
by: =?Utf-8?B?U2NvdHQ=?= | last post by:
I have seen many articles describing why versioning web services are important. I have a scenario that I would like to propose to seek a solution. I have a publicly consumable web service. Two...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.