views:

246

answers:

3

I'm having a bit of difficulty passing a reference type between webservices.

My set up is as follows.

I have a console application that references two web-services:

  1. WebServiceOne
  2. WebServiceTwo

WebServiceOne declares the details of a class I am using in my console application...let's call it MyClass.

My console application calls WebServiceOne to retrieve a list of MyClass.

It then sends each MyClass off to WebServiceTwo for processing.

Within in the project that holds WebServiceTwo, there is a reference to WebServiceOne so that I can have the declaration of MyClass.

The trouble I'm having is that, when I compile, it can't seem to determine that the MyClass passed from the console application is the same as the MyClass declared in WebServiceOne referenced in WebServiceTwo.

I basically get an error saying Console.WebServiceOne.MyClass is not the same as MyProject.WebServiceOne.MyClass.

Does anyone know if doing this is possible? Perhaps I'm referencing WebServiceOne incorrectly? Any idea what I might be doing wrong?

My only other option is to pass each of the properties of the reference type directly to WebServiceTwo as value types...but I'd like to avoid that since I'd end up passing 10-15 parameters.

Any help would be appreciated!

A: 

Move the types to a separate assembly and ensure that both services use this. In the web service reference there is probably some autogenerated code called Reference.cs. Alter this to use your types.

Edit: To reflect comments

In that case take the reference.cs from that web service you cannot control use it as the shared type.

Preet Sangha
Not sure I can do that since WebServiceOne is controlled by a third party. Basically, the class declaration they make available is all I have to work with. I'm just trying to figure out how to pass that value on again to another webservice that also references WebServiceOne.
mezoid
+1  A: 

I had a chat with one of the more senior guys at my work and they proposed the following solution that has worked out well for me.

The solution was to use a Data Transfer Object and remove the reference to WebServiceOne in WebServiceTwo.

Basically, in WebServiceTwo I defined a representation of all the value type fields needed as BenefitDTO. This effectively allows me to package up all the fields into one object so I don't have to pass each of them as parameters in a method.

So for the moment, that seems to be the best solution...since it works and achieves my goal.

It's likely that I didn't explain my question very well...which explains why no one was able to help...

But thanks anyway! :-)

mezoid
A: 

Your error message explains the problem. The proxy class on the client side is not the same type as the original class on the server side, and never will be. Whether it's a reference type or a value type is irrelevant to how it works.

I don't quite understand what your exact problem is, but here are a few guesses:

  • If you are trying to compare two objects for equality, then you will have to write your own compare function that compares the values of each significant property/field in turn.
  • If you are trying to copy an object from one service to the other, then you will have to write your own copy function that copies the values of each significant property/field in turn.

If you were using WCF, you would have the option of bypassing all this and just sharing one class definition between the client and both services.

Christian Hayter