views:

55

answers:

4

I have classes that are needed in both my web service and my server. For example, I have a class named Order that I'd like to send from my server to the web service and vice-versa.

Problem is that the class in the server is Order and the one on the web service is localhost.Order, and it is impossible to convert between them, even though they are built from the very same code. Error is cannot convert from 'Order[]' to 'localhost.Order[]'.

What can I do? Thank you very much.

+3  A: 

when you add reference to web service you can specify which classes to reuse. by default it generates classes based on WDSL that web service produce.

Andrey
How can I specify these on VS2008?
iTayb
+1  A: 

You should maybe have a look at WCF services:

http://msdn.microsoft.com/en-us/library/bb332338.aspx

I've used these on a few projects where both have references to a shared library, and one web site will request one of these objects via a WCF service call from another site. It's very clean, and it opens up other options for transport/security which can be very useful.

Paddy
Thank you, but I'll have to stick with ASMX. It's for a school project.
iTayb
+2  A: 

The namespace used is determined by the name you give the reference when you add it.

For more information see this answer to a similar question:

http://stackoverflow.com/questions/1439703/unable-to-cast-object-of-type-myobject-to-type-myobject

Neil Barnwell
A: 

The question appears to suggest that you are using ASMX Web Services. If so, you have your work cut out for you.

Jelle Druyts wrote an extension for ASMX that can do, more or less, what you're asking. You have to configure your shared types at the machine level (machine.config). It's not pretty.

There's also a fix for that extension to make it work with nullable types.

Good luck getting this to work with Visual Studio 2008 or on Vista/Windows 7. You'll be OK if you're still running XP with VS 2005.

If you can, you really should consider using WCF for the client proxy instead, since WCF makes it very easy to share types. In fact, the Visual Studio 2008 integration does this by default; you just need to make sure your client project references the assembly containing the service types.

Aaronaught