473,382 Members | 1,107 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,382 software developers and data experts.

Question about web services and sharing classes

How can a class be shared between a web service and a client that consumes
the web service?

Suppose I have a Class Libraray with the following simple class:

Public Class SimpleClass
Private _AnInteger As Integer

Public Property AnInteger As Integer
Get
Return _AnInteger
End Get
Set(ByVal Value As Integer)
_AnInteger = Value
End Set
End Property
End Class

This is compiled to a .DLL.

Now, I create a Web Service project and Reference the ClassLibrary and then
add a Web Method as follows:

<WebMethod()> _
Public Sub DoSomething(ByVal sc As SimpleClass)
'Do Something with sc here
End Sub
Finally, I create a Windows Forms Application to consume the web service.
I add the Web Reference to the web service and also Reference the
SimpleClass library and everything looks OK so far, until I try to use
them. Here is an example

Private Sub Button1_Click(...) Handles Button1.Click
'Declare an instance of the web service
Dim ws As New localhost.Service1

'Create an instance of the simple class
Dim sc As New SimpleClass

'Now call the web service method:
ws.DoSomething(sc) '<------- Error here
End Sub

When I try this, it tells me that it cant convert an instance of
SimpleClass to localhost.SimpleClass.

If I change the instantiation of the simple class as follows:

Dim sc As New localhost.SimpleClass

Then it seems to work OK. But my problem is that if SimpleClass in the
ClassLibrary has methods and not just properties, those methods are not
available in the localhost.SimpleClass version, just the properties.

Is it possible to share a ClassLibrary in this manner?

Any assistance would be appreciated.

Chris

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 18 '05 #1
3 1343
Your code didn't work, not because your class cannot be shared between the
server and client, but because the proxy has declared the method argument as
being localhost.SimpleClass ... arrange your proxy class, and it will do
fine ...

However, you are defeating the whole idea behind web services when you want
to have the class shared ... You are totally in an RPC mind set, why then
use a message oriented technology and architecture ? Do you really mean to
do your class sharing outside of your own context (with partners and such)?
why ? if it is more like an intranet setting, Enterprise Services stays your
best choice, most performing, most secure and richest features ... if it is
a problem with going through firewalls and such (although I don't see why
you would really need RPC outside of firewalls, if you think a little about
it) why not go for remoting (it can use http, it can go through firewalls
....etc. Well, I have lots of reasons for not recommending it, but still, if
you need RPC so badly across firewalls...).
If it is about interop, then class sharing is totally out of question ...

"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:5h*****************************@40tude.net...
How can a class be shared between a web service and a client that consumes
the web service?

Suppose I have a Class Libraray with the following simple class:

Public Class SimpleClass
Private _AnInteger As Integer

Public Property AnInteger As Integer
Get
Return _AnInteger
End Get
Set(ByVal Value As Integer)
_AnInteger = Value
End Set
End Property
End Class

This is compiled to a .DLL.

Now, I create a Web Service project and Reference the ClassLibrary and then add a Web Method as follows:

<WebMethod()> _
Public Sub DoSomething(ByVal sc As SimpleClass)
'Do Something with sc here
End Sub
Finally, I create a Windows Forms Application to consume the web service.
I add the Web Reference to the web service and also Reference the
SimpleClass library and everything looks OK so far, until I try to use
them. Here is an example

Private Sub Button1_Click(...) Handles Button1.Click
'Declare an instance of the web service
Dim ws As New localhost.Service1

'Create an instance of the simple class
Dim sc As New SimpleClass

'Now call the web service method:
ws.DoSomething(sc) '<------- Error here
End Sub

When I try this, it tells me that it cant convert an instance of
SimpleClass to localhost.SimpleClass.

If I change the instantiation of the simple class as follows:

Dim sc As New localhost.SimpleClass

Then it seems to work OK. But my problem is that if SimpleClass in the
ClassLibrary has methods and not just properties, those methods are not
available in the localhost.SimpleClass version, just the properties.

Is it possible to share a ClassLibrary in this manner?

Any assistance would be appreciated.

Chris

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 18 '05 #2
Hi Chris,

No you can't do this unfortunately with standard Web Services. I've also
often wanted to do this because I have many application where the same
business objects sit both on the client and the server. It seems logicial
that you should be able to pass an object from client to server, but the
plain WebService architecture MS has doesn't work that way.

As Malek pointed out Web Services work of Proxy objects which are actually
very different than the 'live' object that is passed back from the server.
For one thing it has a completely different structure as methods aren't
proxied.

SO your workaround in these scenarios is to copy properties or use smart
classes to ship over the wire that hold all of their data in a format that's
easy to reattach in some way. FOr example, you can pass datasets back and
forth and simply pick up the data sets and attach them to your client
object.
+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:5h*****************************@40tude.net...
How can a class be shared between a web service and a client that consumes
the web service?

Suppose I have a Class Libraray with the following simple class:

Public Class SimpleClass
Private _AnInteger As Integer

Public Property AnInteger As Integer
Get
Return _AnInteger
End Get
Set(ByVal Value As Integer)
_AnInteger = Value
End Set
End Property
End Class

This is compiled to a .DLL.

Now, I create a Web Service project and Reference the ClassLibrary and then add a Web Method as follows:

<WebMethod()> _
Public Sub DoSomething(ByVal sc As SimpleClass)
'Do Something with sc here
End Sub
Finally, I create a Windows Forms Application to consume the web service.
I add the Web Reference to the web service and also Reference the
SimpleClass library and everything looks OK so far, until I try to use
them. Here is an example

Private Sub Button1_Click(...) Handles Button1.Click
'Declare an instance of the web service
Dim ws As New localhost.Service1

'Create an instance of the simple class
Dim sc As New SimpleClass

'Now call the web service method:
ws.DoSomething(sc) '<------- Error here
End Sub

When I try this, it tells me that it cant convert an instance of
SimpleClass to localhost.SimpleClass.

If I change the instantiation of the simple class as follows:

Dim sc As New localhost.SimpleClass

Then it seems to work OK. But my problem is that if SimpleClass in the
ClassLibrary has methods and not just properties, those methods are not
available in the localhost.SimpleClass version, just the properties.

Is it possible to share a ClassLibrary in this manner?

Any assistance would be appreciated.

Chris

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 18 '05 #3
>> On Sat, 28 Feb 2004 00:35:48 -0000, Malek wrote:

Thanks for the response. Perhaps web services are not the way to go for my
project. We offer a service in which all the equipment needed to carry
out that service is maintained at our central facility. We want to give
clients the ability to submit a 'job' over the internet to use our service.
I am creating a 'Thin Client' app to allow them to do this. The web
service will only be accessed by this 'Thin Client' app and not made
available otherwise. This 'Thin Client' will allow the customer to gather
necessary data at their end and submit to our central facility for
processing. We would then provide them with a report with the results of
the processing.

Web services seemed to be a simple way to allow the client app to
communicate with our servers. Do you think remoting would be a more
appropriate method for this type of project?

Thanks again

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 18 '05 #4

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

Similar topics

11
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
3
by: Matt D | last post by:
I've got two web services that use the same data types and that clients will have to consume. I read the msdn article on sharing 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...
1
by: Joe | last post by:
While I understand that Server Side Includes still work, I realize it's not the best practice for sharing code such as a common set of includes between screens. In ASP.NET I've already built...
6
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public...
0
by: Daniel P. | last post by:
http://danutp.blogspot.com/ Web Services - sharing data between client and server Dealing a lot with web services a friend of mine (Ehsan Samani) and I ran into another issue: when we move...
25
by: Brian | last post by:
Can some one please tell me what I'm doing wrong. I'm trying to create a class called Dog, but Visual Basic tells me that I can't enter Wolf.age....why is this? Public Class Form1 Public Class...
4
by: cwc5w | last post by:
I have two classes. One with a regular destructor and the other with a virtual destructor. e.g. class x { ~x(){} } vs
16
by: =?Utf-8?B?U3RldmUgQmFya2Vy?= | last post by:
WCF Question Hi guys, I’m pretty new to WCF, and have a basic question about how it works. I’m trying to use WCF to write an “SOA-system”, and am having a few problems. The...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.