re: Webservice returns<p align=left>Hi People,</p> <p align=left> </p> <p align=left>I am now returning to web services and have pretty much forgotten how stuff works. <img alt=Sad src="http://forums.microsoft.com/MSDN/emoticons/emotion-6.gif"></p> <p align=left> </p> <p align=left>I have a web service that returns a custom type.  I need the webmethod to accept a parameter of the *assembly* type as opposed to the WSDL/Webservice interpretation of the type.</p> <p align=left> </p> <p align=left>Does this make sense?</p> <p align=left> </p> <p align=left>I am expecting to share the assembly of classes between the web service and the client.  This way I can use the same classes.  Only I am not sure how I am supposed to achieve this when the WSDL is generated automatically and generated using web service versions of my classes.</p> <p align=left> </p> <p align=left>Thanks in advance for any help</p> <p align=left> </p> <p align=left>koder</p>© 2009 Microsoft Corporation. All rights reserved.Tue, 24 Jun 2008 13:27:10 Ze8d5253c-a225-4f56-897f-f0c29a137526http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#e8d5253c-a225-4f56-897f-f0c29a137526http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#e8d5253c-a225-4f56-897f-f0c29a137526iKIT Solutions Ltdhttp://social.msdn.microsoft.com/Profile/en-US/?user=iKIT%20Solutions%20Ltdre: Webservice returns<p align=left>Hi People,</p> <p align=left> </p> <p align=left>I am now returning to web services and have pretty much forgotten how stuff works. <img alt=Sad src="http://forums.microsoft.com/MSDN/emoticons/emotion-6.gif"></p> <p align=left> </p> <p align=left>I have a web service that returns a custom type.  I need the webmethod to accept a parameter of the *assembly* type as opposed to the WSDL/Webservice interpretation of the type.</p> <p align=left> </p> <p align=left>Does this make sense?</p> <p align=left> </p> <p align=left>I am expecting to share the assembly of classes between the web service and the client.  This way I can use the same classes.  Only I am not sure how I am supposed to achieve this when the WSDL is generated automatically and generated using web service versions of my classes.</p> <p align=left> </p> <p align=left>Thanks in advance for any help</p> <p align=left> </p> <p align=left>koder</p>Fri, 21 Sep 2007 16:20:51 Z2007-09-24T09:33:59Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#35460f23-fa16-4df1-9354-2933874e1163http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#35460f23-fa16-4df1-9354-2933874e1163Peter Ritchiehttp://social.msdn.microsoft.com/Profile/en-US/?user=Peter%20Ritchiere: Webservice returnsSOA is data-oriented, not object-oriented.  XML Web Services don't transfer objects, they transfer data.  What the wizards do for you is to create object-oriented types based on the WSDL schema so you can more easily process the response from a Web Service.  The type generated from the WSDL is not the same type as that used on the server. <p align=left><font face=Arial size=2></font> </p>The Visual Studio wizards don't support it, but the <a title="http://msdn2.microsoft.com/en-us/library/7h3ystb6(VS.80).aspx" href="http://msdn2.microsoft.com/en-us/library/7h3ystb6(VS.80).aspx">WSDL.EXE </a>tool allows you to customize the generation of the code from the WSDL schema information, so you could get it to re-use existing types.  See also <a title="http://msdn2.microsoft.com/en-us/library/system.xml.serialization.advanced.schemaimporterextension.aspx" href="http://msdn2.microsoft.com/en-us/library/system.xml.serialization.advanced.schemaimporterextension.aspx">http://msdn2.microsoft.com/en-us/library/system.xml.serialization.advanced.schemaimporterextension.aspx</a>Fri, 21 Sep 2007 16:47:10 Z2007-09-24T09:33:59Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#79fb1697-61d0-4443-9692-ccc040953d11http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#79fb1697-61d0-4443-9692-ccc040953d11John Saundershttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20Saundersre: Webservice returns<p>Personally, I recommend against any attempts to share types between the client and the server. This can lead to code being designed in the erroneous belief that the client and server instances are the same object. I prefer to design as though the client and server were written in different languages and running on different platforms. </p> <p align=left> </p> <p align=left>That way, when someone above my pay grade decides that we have to support a different platform, we will be able to do so.</p> <p align=left> </p>Fri, 21 Sep 2007 22:11:06 Z2007-09-21T22:11:06Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#fdf81ce7-5580-464f-a58b-ca030ef0b268http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#fdf81ce7-5580-464f-a58b-ca030ef0b268iKIT Solutions Ltdhttp://social.msdn.microsoft.com/Profile/en-US/?user=iKIT%20Solutions%20Ltdre: Webservice returns<p>Thanks to both of you.  I understand what both of you are saying but while I agree in principle to building the web service language agnostic, i know that the &quot;someones above my pay grade&quot; would rather use the classes on both sides as they believe they will remain on the windows platform/c#/blah blah.  </p> <p align=left> </p> <p align=left>But - i will try to return an xml fragment or something instead and see how it flies.  Should I return the xml of the object as a string or xmldocument or is there a type I am missing?</p> <p align=left> </p> <p align=left>koder</p> <p align=left><font face=Arial size=2></font> </p>Fri, 21 Sep 2007 23:49:25 Z2007-09-21T23:49:25Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#81e8f1d7-f42e-4c0f-a278-84a4979102fehttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#81e8f1d7-f42e-4c0f-a278-84a4979102feJohn Saundershttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20Saundersre: Webservice returns<p align=left><font face=Arial size=2>After reading this reply, I'm no  longer clear on what you're trying to do. I thought you had a web service that returns an object of a type, for instance, MyServerNameSpace.MyEntityType. I thought you wanted your client to receive it as MyServerNameSpace.MyEntityType instead of MyWebReference.MyEntityType.</font></p> <p align=left> </p> <p align=left>If that is true, then just have your web service return MyServerNameSpace.MyEntityType, then find some hack to cause the proxy classes to use that type.</p> <p align=left> </p> <p align=left>I suggest that you be careful, and get this working first with a single type. I've seen a great deal of confusion in developers who have tried to do this. That's why I recommend against it.</p> <p align=left> </p>Fri, 21 Sep 2007 23:55:07 Z2007-09-21T23:55:07Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#c4777d4b-6507-4e19-a715-55719bb49beahttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#c4777d4b-6507-4e19-a715-55719bb49beaiKIT Solutions Ltdhttp://social.msdn.microsoft.com/Profile/en-US/?user=iKIT%20Solutions%20Ltdre: Webservice returns<p>You are right. I originally wanted to return objects as MyServerNameSpace.MyEntityType instead of MyWebServiceReference.MyEntityType as this is how th current developers where I work have always done it and like it.</p> <p align=left> </p> <p align=left>However, I am agree with the two of you that I should not do this.  I already know that when you start using words like &quot;hack&quot; it is not a good start.  On top of which trying to keep the generated files in sync will be a pain.  I would rather just pass the &quot;data&quot; over the wire and leave it up to the client to deserialise the object.</p> <p align=left> </p> <p align=left>I suppose the question i was asking before was really this:</p> <p align=left> </p> <p align=left>Is the MyWebReference.MyEntityType result standard xml or should I deserialize the object manually on the server and pass it out?</p> <p align=left> </p> <p align=left>eg:</p> <p align=left> </p> <p align=left>publlic class CustomObject{}</p> <p align=left> </p> <p align=left>public class MyWebService : WebService</p> <p align=left>{</p> <p align=left> </p> <p align=left> </p> <p align=left>[WebMethod]</p> <p align=left>public CustomObject GetAnObject()</p> <p align=left>{</p> <p align=left>return new CustomObject();<br>}</p> <p align=left> </p> <p align=left>[WebMethod]</p> <p align=left>public string GetAnotherObject()</p> <p align=left>{</p> <p align=left>//serialize the object</p> <p align=left>string returnValue = MySerializer.Serialize(new CustomObject());</p> <p align=left>return returnValue;</p> <p> </p> <p align=left> </p> <p align=left>}</p> <p align=left> </p> <p align=left>Do you see?  I can pass back as CustomObject or string or something else.  I have worked with XML gateways which return you plain string which you decide how to instantiate.  This is normally down to the caller to deserialize into a custom class.</p> <p align=left> </p> <p align=left>Maybe I'm making more of this than i should.   Could a NON .NET application understand the return value CustomObject?  Would using string be more accessible?</p> <p align=left> </p>Sat, 22 Sep 2007 07:50:47 Z2007-09-22T07:50:47Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#db216563-84ee-42fe-a564-270b163bfedahttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#db216563-84ee-42fe-a564-270b163bfedaJohn Saundershttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20Saundersre: Webservice returns<p>You can go ahead and return CustomObject. The reason is that ASP.NET will do the serialization for you, and will do it in a way that any client will be able to understand.</p> <p align=left> </p> <p align=left>On the client side, you can use the actual MyService.CustomObject, as long as you instantiate it from MyWebReference.CustomObject:</p> <p align=left><font face=Arial size=2> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p align=left> </p> <p align=left>using (MyWebReference.Service svc = new MyWebReference.Service())</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>MyWebReference.CustomObject mwrco = svc.WebMethod();</p> <p align=left>MyService.CustomObject msco = new MyService.CustomObject();</p> <p align=left>msco.Property1 = mwrco.Property1;</p> <p align=left>msco.Property2 = mwrco.Property2;</p> <p align=left> </p> <p align=left>// or</p> <p align=left>// MyService.CustomObject msco = new MyService.CustomObject(mwrco); // but this is a little dangerous</p></blockquote> <p align=left>}</p> <p align=left> </p></div></div> <p align=left></font> </p>Sun, 23 Sep 2007 01:07:18 Z2007-09-24T09:08:46Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#e075072b-7ccf-42c2-827f-442db20410bdhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#e075072b-7ccf-42c2-827f-442db20410bdiKIT Solutions Ltdhttp://social.msdn.microsoft.com/Profile/en-US/?user=iKIT%20Solutions%20Ltdre: Webservice returns<p align=left><font face=Arial size=2>Thanks People for you help.  I messed around with it this morning and got a greater handle on what you guys were talking about.</font></p> <p align=left> </p> <p align=left>I have decided to return the web reference types and deserialize them into the client side assembly types instead.  Makes more sense to me that a web service provides the dat - essentially in xml - and it is up to the client to instantiate it into what ever the hell it wants to.</p> <p align=left> </p> <p align=left>I use the XmlSerializer to serialize and deserialize depending on whether i am getting data or sending data.  Does anyone see any problem with this?</p> <p align=left> </p> <p align=left>Thanks again!</p>Mon, 24 Sep 2007 09:33:35 Z2007-09-24T09:33:35Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#9008fa6b-2f50-4c28-bb9f-977e46d7723fhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/e8d5253c-a225-4f56-897f-f0c29a137526#9008fa6b-2f50-4c28-bb9f-977e46d7723fPaymonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Paymonre: Webservice returnsHumm... According to this: <a href="http://www.geeks.ltd.uk/Knowledgebase/Service-Object-Orientation.html">http://www.geeks.ltd.uk/Knowledgebase/Service-Object-Orientation.html</a>: Object Orientation is about internals of a system, while Service Orientation is about external communication. OO is concerned about flexibility and abstraction, while SOA's concern is compliance with standards, simplicity and protocols. <hr size="1" align="left" width="25%">PaymonTue, 24 Jun 2008 13:27:10 Z2008-06-24T13:27:10Z