<p>I'm still 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!</p>

<p>Let's say I have a standard business object "Contact" in the <em>Business</em> 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.</p>

<p>Now, I also then create a utility method that takes a "Contact" and does some magic with it, like <code>Utils.BuyContactNewHat()</code> say. Which of course takes the Contact of type <code>Business.Contact</code>.</p>

<p>I then go back to my client application and want to utilise the <code>BuyContactNewHat</code> method, so I add a reference to my <em>Utils</em> namespace and there it is. However, a problem arises with:</p>

<pre><code>Contact c = MyWebService.GetContact("Rob);
Utils.BuyContactNewHat(c); // &lt;&lt; Error Here
</code></pre>

<p>Since the return type of <code>GetContact</code> is of <code>MyWebService.Contact</code> and not <code>Business.Contact</code> 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.</p>

<p>So, is there an "easier" way to deal with this type of mismatch? I was considering perhaps trying to create a generic converter class that uses reflection to ensure two objects have the same structure than simply transferring the values across from one to the other.</p>

[{'answer_id': 6704, 'author': 'Lance Fisher', 'author_id': 571, 'author_profile': 'https://Stackoverflow.com/users/571', 'pm_score': 4, 'selected': True, 'text': "<p>You are on the right track.  To get the data from the proxy object back into one of your own objects, you have to do left-hand-right-hand code.  i.e. copy property values.  I'll bet you that there is already a generic method out there that uses reflection.</p>\n\n<p>Some people will use something other than a web service (.net remoting) if they just want to get a business object across the wire.  Or they'll use binary serialization.  I'm guessing you are using the web service for a reason, so you'll have to do property copying.</p>\n"}, {'answer_id': 8029, 'author': 'd4nt', 'author_id': 1039, 'author_profile': 'https://Stackoverflow.com/users/1039', 'pm_score': 2, 'selected': False, 'text': "<p>You don't actually have to use the generated class that the WSDL gives you. If you take a look at the code that it generates, it's just making calls into some .NET framework classes to submit SOAP requests. In the past I have copied that code into a normal .cs file and edited it. Although I haven't tried this specifically, I see no reason why you couldn't drop the proxy class definition and use the original class to receive the results of the SOAP call. It must already be doing reflection under the hood, it seems a shame to do it twice.</p>\n"}, {'answer_id': 395263, 'author': 'Mark', 'author_id': 49395, 'author_profile': 'https://Stackoverflow.com/users/49395', 'pm_score': 1, 'selected': False, 'text': '<p>I would recommend that you look at writing a Schema Importer Extension, which you can use to control proxy code generation. This approach can be used to (gracefully) resolve your problem without kludges (such as copying around objects from one namespace to another, or modifying the proxy generated reference.cs class only to have it replaced the next time you update the web reference).</p>\n\n<p>Here\'s a (very) good tutorial on the subject:</p>\n\n<p><a href="http://www.microsoft.com/belux/msdn/nl/community/columns/jdruyts/wsproxy.mspx" rel="nofollow noreferrer">http://www.microsoft.com/belux/msdn/nl/community/columns/jdruyts/wsproxy.mspx</a></p>\n'}]
['https://Stackoverflow.com/questions/6681', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/832/']