473,320 Members | 1,846 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.

Share Class between Windows app and ASP.NET website

All,

I created a class in a windows application and I'd like to be able to
pass an instance of that class as a method parameter to a web service.
The class contains 100 variables. I tried adding a new class to the
web service (using VS Web Developer Express) and recreated the
variables to match what was in the windows application class but when
I try to pass an object as a parameter I'm getting a 'Cannot
implicitly convert from winform.type to webservice.type'.

Is there an *easy* way to share a class between my win form app and
the web service so I can pass objects back and forth?

Thanks in advance.
Jan 8 '08 #1
4 2647
Well, normally the proxy will create an entirely unrelated, meta-data
based type. With WCF there are a few tricks you can pull to share the
type more directly (i.e. without using svcutil.exe, which would do the
same thing as wsdl.exe) - but otherwise I think you have to stick to
treating the metadata version as just that: raw data.

You could perhaps write a utility method to convert between the two?
By copying the properties (either by hand, or by using some tricks
like reflection to do it more gracefully) or possibly (less nice) by
serialization / deserialization. Actually, you might even be able to
add cast operators to your main class (casting to the proxy class)
[not sure if this is a great idea]

Marc
Jan 8 '08 #2
Hi,

If you put that class in a shared dll then both projects can have a
reference to it. Inaddition if the class support a Constructor or a method
that receive all the variables then either program can create an instance
that is the same in both programs. The only thing to note though is that you
will have two instances that will be the same at that point but that can be
modified independently afterwards.

Also take a look at Serialization, it could also solve your problem.

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Looch" <lu**********@yahoo.comwrote in message
news:33**********************************@v29g2000 hsf.googlegroups.com...
All,

I created a class in a windows application and I'd like to be able to
pass an instance of that class as a method parameter to a web service.
The class contains 100 variables. I tried adding a new class to the
web service (using VS Web Developer Express) and recreated the
variables to match what was in the windows application class but when
I try to pass an object as a parameter I'm getting a 'Cannot
implicitly convert from winform.type to webservice.type'.

Is there an *easy* way to share a class between my win form app and
the web service so I can pass objects back and forth?

Thanks in advance.

Jan 8 '08 #3
Dear all,

I have a similar problem in a Visual Studio solution with two projects:

Project 1: "Normal" class library which contains public business objects. The DLL created by this project may be called directly by the user (as a DLL assembly).

Project 2: A WCF server containing services where I want to use the *SAME* business objects as parameters in public "ServiceContract" functions. (This is important as I do not want to write 2 versions of each business object).

But this seems somewhat impossible, as
1) It seems impossible to add the "DataContract"/"DateMember" attributes to objects in BusinessServer.dll, and also
2) It seems impossible to define the business objects in the WCF-server project and have them accessible/exposable by Project 1.

So, HOW TO REUSE BUSINESS OBJECTS BOTH AS "NORMAL" BUSINESS OBJECTS IN THE DLL, *AND* AS "DataContract" OBJECTS IN WCF SERVICE?

This type of code reuse seems to me to be very important.

Best regards,
Bjørn Sigurd Johansen
Norway
Jul 27 '08 #4

You'll want to check out this blog entry:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!158.entry

...

You have to remember that with WCF, you have the ability to expose DotNet
code to non-DotNet clients.
Thus the "client side proxy".

In a DotNet to DotNet world, you don't necessarily want that. You want
things on both sides about the same....
and WCF is a service.

The blog entry should help.


<Bjorn Sigurd Johansenwrote in message
news:20********************************@spidersolu tions.no...
Dear all,

I have a similar problem in a Visual Studio solution with two projects:

Project 1: "Normal" class library which contains public business objects.
The DLL created by this project may be called directly by the user (as a
DLL assembly).

Project 2: A WCF server containing services where I want to use the
*SAME* business objects as parameters in public "ServiceContract"
functions. (This is important as I do not want to write 2 versions of
each business object).

But this seems somewhat impossible, as
1) It seems impossible to add the "DataContract"/"DateMember" attributes
to objects in BusinessServer.dll, and also
2) It seems impossible to define the business objects in the WCF-server
project and have them accessible/exposable by Project 1.

So, HOW TO REUSE BUSINESS OBJECTS BOTH AS "NORMAL" BUSINESS OBJECTS IN THE
DLL, *AND* AS "DataContract" OBJECTS IN WCF SERVICE?

This type of code reuse seems to me to be very important.

Best regards,
Bjørn Sigurd Johansen
Norway

Jul 28 '08 #5

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

Similar topics

5
by: JohnFol | last post by:
I am using the Win23 API WNetCancelConnection2 and can sucessfully make a connection to a share within my class. The class is called from a Windows Form based test harness. When I instantiate...
6
by: Tony Fonager | last post by:
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application. (I have simplified my code, to make my project easier to...
8
by: Tony Fonager | last post by:
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application. (I have simplified my code, to make my project easier to...
0
by: Michiel | last post by:
Here's the situation: Windows XP SP2 with VS .Net 2003 Web project located on: Windows Server 2003 IIS 6 & Remote Debugging Website with document root pointing to UNC share on: Windows...
3
by: musosdev | last post by:
Hi guys Okay, I've setup my projects to open and compile fine in VS2005 using FPSE and remote web, but it's *really* slow. So I thought I'd have a go at doing it the normal way, by loading from...
3
by: Bob Peek | last post by:
I would like to share code between several web sites that exist as virtual directories under a single site. It appears that I have to create an app_code directory under each virtual root in order...
15
by: Neo | last post by:
Hello All, I found that ASP.net website only accepts code withing site directory. This creates big hurdle in shairng code. How to share code between two websites, like the way share between two...
6
by: tendim | last post by:
G'day group. Currently our organization us using VB6 based applications, and I am trying to push forward and migrate some of the smaller things to VB.NET, eventually migrating all applications...
0
by: GregInHouston2 | last post by:
I am attempting to access the files on a share on a server in my network so I can list the files there on an intranet web page. At this point, the share permissions and the NTFS permissions are...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
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: 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.