Accessing Web Services with Silverlighthttp://forums.silverlight.net//46.aspx/1?Accessing+Web+Services+with+SilverlightDiscussions about using WCF in Silverlight, accessing SOAP and REST web services, and using XML, JSON, RSS and Atom data.”Mon, 01 Jan 0001 00:00:00 -050046151306http://forums.silverlight.net//p/60518/151306.aspx/1?Best+practices+for+getting+data+throught+WCF+service+Best practices for getting data throught WCF service ? <p>Hello Silverlight coders !</p> <p>I have my Silverlight Application &quot;MySLApp&quot;, a WCF service &quot;MyService&quot;, data on the server stored as XML &quot;MyData&quot; and coming from DataSet &quot;MyXSD&quot;, that is used to share MyData on all software consuming it in my company.</p> <p>Now that Silverlight 2 does not supports Datasets, I have searched for&nbsp;the best way to have this data the most &quot;strong typed&quot; as possible in MySLApp.</p> <p>&nbsp;I have tried the following :</p> <ul> <li> <div>Linq to XSD : not compiling because of the type ArrayOfXElement not known by Silverlight</div> </li><li> <div>Generate classes with XSD.exe : working but classes are only containers, there are no constraints and references between objects</div> </li><li> <div>Linq to XML : ok but raw XML</div> </li></ul> <p>There are good samples on Linq to SQL but MyData&nbsp;comes from a dataset. There are very good samples on Linq to XSD but Silverlight can't handle generated code.</p> <p>What is the best way to achieve this ?</p> <p>Thank you.<br> <br> </p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2008-12-22T14:56:41-05:00151310http://forums.silverlight.net//p/60518/151310.aspx/1?Re+Best+practices+for+getting+data+throught+WCF+service+Re: Best practices for getting data throught WCF service ? <p>If you have an XSD for the data, you could use <a class="" href="http://msdn.microsoft.com/en-us/library/x6c1kb0s.aspx"> xsd.exe</a> to generate classes from the schema. Then share those classes from the WCF after deserializing the XML to the objects. Otherwise you're stuck with untyped XML.</p> <p>One other option is to pass the raw XML via WCF and then deserialize it to objects in your Silverlight application. Then you'll be working with objects and that will serve as validation of the XML.</p> 2008-12-22T15:02:07-05:00151712http://forums.silverlight.net//p/60518/151712.aspx/1?Re+Re+Best+practices+for+getting+data+throught+WCF+service+Re: Re: Best practices for getting data throught WCF service ? <p>Thank you bryant for this answer. I have tried this way, but my question was &quot;Is this the best way ?&quot;.</p> <p>As Linq to XSD is definitely what I assume to be the best solution to handle Dataset in a non-dataset environment like Silverlight, I was looking to something very similar that could be done in Silverlight. Sharing classes generated by Xsd.exe is fine (it is also possible to generate DataContrat with Svcutil.exe), but how can I perform Linq queries on them ?</p> <p>&nbsp;</p> 2008-12-23T08:41:33-05:00175633http://forums.silverlight.net//p/60518/175633.aspx/1?Re+Re+Best+practices+for+getting+data+throught+WCF+service+Re: Re: Best practices for getting data throught WCF service ? <p>hello aixchile,</p> <p>Did you get to resolve which one is the best way? If you can help me with my issue, that will be great! I am looking for a tool (if it is there out) that creates objects that can be used by Silverlight application. Currently I am creating my own classes and a helper class that will actually do the conversions from XElements to Entities and Entities back to XML in order for my silverlight application to communicate with data. I know that Linqtoxsd does not work with silverlight application. Is there a way out there that is more like auto generated code usable by silverlight yet?</p> 2009-02-17T23:57:37-05:00175762http://forums.silverlight.net//p/60518/175762.aspx/1?Re+Re+Best+practices+for+getting+data+throught+WCF+service+Re: Re: Best practices for getting data throught WCF service ? <p>Well... I now think that the best way depends on where your data is.</p> <ul> <li>If your data is stored in SQL or any ADO.Net datasource : use Linq to Entities in your service and serve entities as DataContracts throught Silverlight (I have not tested this but this sample looks great : http://www.codeproject.com/KB/silverlight/MySilverlightDataApp.aspx ). Also careful with this and SqlServer 2008 : Linq classes do not handle geometry and geography data......<br> </li><li>If your data is stored the Xml way, you should have or build your DataSets and use Xsd.exe to generate classes (using&nbsp; xsd.exe /classes DstMyData.xsd /out:outdir). Those classes can be directly added to your Silverlight project to handle Xml data (by manually loading xml data file with XDocument and putting the results in a DstMyData object), and / or can be used as DataContracts throught a WCF service. (this post was helpful : http://www.keithelder.net/blog/archive/2008/11/02/Creating-a-REST-WCF-Service-From-an-Existing-XSD-Schema.aspx)<br> </li><li>... (if anyone can send here any other method, this could be great)<br> </li></ul> <p>I used the second method and it works really great. The real big deal is to load the data to the classes generated by Xsd.exe (because the generated classes do not have constraints like real dataset classes do). But when that job is done, you can query your classes via Linq in a really powerful SQL like way<br> <br> So the tool you're looking for may be Xsd.exe if your data is xml, and should be Visual Studio and Linq to classes if your data is SQL or any database.</p> <p>Hope it helps ! <br> </p> 2009-02-18T07:32:08-05:00182821http://forums.silverlight.net//p/60518/182821.aspx/1?Re+Re+Best+practices+for+getting+data+throught+WCF+service+Re: Re: Best practices for getting data throught WCF service ? <p>Hello aixchile,</p> <p>&nbsp;The xsd.exe solution you describe is exactly what I need. I would like to create classes from my .xsd file and add them to my Silverlight app.</p> <p>&nbsp;I've tried this but my app will not compile and is reporting that there is no reference to:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp; <font size="2">System.SerializableAttribute()</font></p> <font size="2"><font size="2"> <p>&nbsp;&nbsp;&nbsp;&nbsp; System.ComponentModel.DesignerCategoryAttribute</p> <p>&nbsp;It looks like this is because I'm trying to do add my class directly into my Silverlight class. Is this possible?</p> <p>&nbsp;Thanks.</p> </font></font> 2009-03-04T13:50:06-05:00182832http://forums.silverlight.net//p/60518/182832.aspx/1?Re+Re+Best+practices+for+getting+data+throught+WCF+service+Re: Re: Best practices for getting data throught WCF service ? <p>&nbsp;In my case, I have simply removed those two attributes, and it id compile.</p> <p>&nbsp;By the way, using generated classes this way won't generate any code for constraints and relations. The generated class is just a data &quot;container&quot;.</p> <p>&nbsp;</p> 2009-03-04T14:27:53-05:00182882http://forums.silverlight.net//p/60518/182882.aspx/1?Re+Re+Re+Best+practices+for+getting+data+throught+WCF+service+Re: Re: Re: Best practices for getting data throught WCF service ? <p>Hi aixchile,</p> <p>Thank you for your solutions. The one actually worked for me was the second point you made and the following website has exactly what I needed - <a href="http://www.keithelder.net/blog/archive/2008/11/02/Creating-a-REST-WCF-Service-From-an-Existing-XSD-Schema.aspx"> http://www.keithelder.net/blog/archive/2008/11/02/Creating-a-REST-WCF-Service-From-an-Existing-XSD-Schema.aspx</a>.</p> <p>I was wondering if it is possible to to have the WCF reference&nbsp; (proxy) in the Silverlight application and also have a REST approach so that we have the pros of REST and yet also have access to&nbsp;the objects created in Service? I tried this but was getting into Binding problems like I can only use BasicHttpBinding while REST is more webHttpBinding?</p> 2009-03-04T16:06:23-05:00182885http://forums.silverlight.net//p/60518/182885.aspx/1?Re+Re+Re+Re+Best+practices+for+getting+data+throught+WCF+service+Re: Re: Re: Re: Best practices for getting data throught WCF service ? <p>I do not use REST as protocol between my Silverlight project and my WCF service, but I know this could be done.<br> </p> <p>Notice that REST relies on SOAP 1.2 which is not supported by Silverlight 2.<br> </p> <p>You still can implement your own REST DataContract serializer. I think you can find some literature about this on MSDN site or on this forum (search &quot;MTOM &#43; Silverlight&quot; ). I remember that you have to parse the data yourself.</p> <p>I'm not an expert of REST with Silverlight, maybe some contributer may help... <br> </p> 2009-03-04T16:16:55-05:00