Hi guys, as you can probably tell from my rep, I have just got my invite so I am a complete n00b! :D First off I would like to say thanks to Jeff and the team for what looks like is going to be an excellent site for the community.
So, my question:
I am still kinda new to the ASP.NET world, so I could be way off base here, but so far this is to the best of my (limited) knowledge!
Lets say I have a standard business object.. "Contact" in the Business namespace.. I write a Web Service to retrieve a Contact's info from a database, and return it. I then write a client application to request said details.
Now, I also then create a utility method that takes a "Contact" and does some magic with it, like Utils.BuyContactNewHat() say.. Which of course takes the Contact of type Business.Contact.
I then go back to my client application and want to utilise the BuyContactNewHat method, so I add a reference to my Utils namespace and there it is. However, a problem arises with:
Contact c = MyWebService.GetContact("Rob);
Utils.BuyContactNewHat(c); // << Error Here
Since the return type of GetContact is of MyWebService.Contact and not Business.Contact as expected.
I understand why this is, because when accessing a web service, you are actually programming against the proxy class generated by the WSDL..
So, is there an "easier" way to deal with this type mismatch? I was considering perhaps trying to create a generic converter class that uses reflection to ensure two objects have the same structure, then simply transferring the values across from one to the other..
Thanks guys, sorry for the long question, just wanted to ensure I explained the problem clearly :)
EDIT: Thanks to Lance Fisher for the answer posted. If anyone can recommend and good methods for the "deep copy" of the objects in question, I would love some input! :)
EDIT: Thanks to Dan Thompson for the idea on copying the code generated by VS via WSDL. I have looked at that sort of scenario before, but the problem is that the services are succeptable to change, meaning the "hack" requires regen, re-copy, re-edit etc. I have +1'd this though since it is a good idea, especially for services that are pretty mature and not likely to change. Thanks.