silverlight 2 has rich networking support soap/xml web services via wcf proxies untyped http...
TRANSCRIPT
![Page 1: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/1.jpg)
Silverlight, RIA & Interop
Les communications en Silverlight
Stève SfartzArchitecte Microsoft France
http://blog.sfartz.comhttp://blogs.msdn.com/ssfartz http://blogs.msdn.com/cloud_computing http://blogs.msdn.com/silverlight_plus_java
![Page 2: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/2.jpg)
Networking
• Silverlight 2 has rich networking support• SOAP/XML Web services via WCF
proxies• Untyped HTTP services (REST, RSS,
ATOM) via HttpWebRequest and WebClient
• Socket support, asset downloads over HTTP, syndication classes, and more
• Also supports WCF duplex services and ADO.NET data services ("Astoria")
![Page 3: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/3.jpg)
Downloading Binary Assets
WebClient wc = new WebClient(); wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(OnProgressChanged); wc.OpenReadCompleted += new OpenReadCompletedEventHandler(OnDownloadCompleted); wc.OpenReadAsync(new Uri("Assets/Flight.wmv", UriKind.Relative)); ... void OnDownloadCompleted(object sender, OpenReadCompletedEventArgs e) { Stream result = e.Result; // TODO: Use result }
![Page 4: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/4.jpg)
Downloading RSS
WebClient wc = new WebClient(); wc.OpenReadCompleted += new OpenReadCompletedEventHandler(OnDownloadCompleted); wc.OpenReadAsync(new Uri ("http://feeds.feedburner.com/AbcNews_TopStories")); ... void OnDownloadCompleted(object sender, OpenReadCompletedEventArgs e) { using (XmlReader reader = XmlReader.Create(e.Result)) { SyndicationFeed feed = SyndicationFeed.Load(reader); RssLB.ItemsSource = feed.Items; // Bind to ListBox } }
![Page 5: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/5.jpg)
Calling a REST Service
HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create (new Uri("http://contoso.com/weather/98052")); request.BeginGetResponse (new AsyncCallback(OnGetResponseCompleted), request); ... private void OnGetResponseCompleted(IAsyncResult ar) { HttpWebRequest request = (HttpWebRequest)ar.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ar);
using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string result = reader.ReadToEnd(); ... } }
![Page 6: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/6.jpg)
WCF Duplex Services
• Silverlight can integrate with WCF duplex services to implement push model for data• Client transmits Net Duplex request
to initiate connection• Server uses WS-Make Connection to
open callback channel for transmitting data
• Client "listens" on callback channelhttp://petermcg.wordpress.com/2008/09/03/silverlight-polling-duplex-part-1-architecture/
![Page 7: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/7.jpg)
Sockets
• Silverlight supports socket connections• System.Net.Sockets.Socket class• Policy file required even for same domain• Connection must be made from client
• Restrictions• Ports 4502-4532 only• Host identified by host name, not IP• TCP only (no UDP)
![Page 8: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/8.jpg)
O’Reilly – Janvier 2009
Data binding controls, LINQ data querying, RESTful and WCF
interfaces, Cross-domain data, ADO.NET Data Services
and the ADO.NET Entity Framework.
Chapitre 8 en teaserConsuming Amazon's RESTful Services with Silverlight 2
![Page 9: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/9.jpg)
Ressources
A Cup of Silverlight http://blogs.msdn.com/silverlight_plus_java
Silverlight & Java Interop http://www.infoq.com/articles/silverlight-java-interop
HTTP Communication and Security with Silverlight http://msdn.microsoft.com/en-us/library/cc838250(VS
.95).aspx
Data-Driven Services with Silverlight 2 http://silverlight2data.com/
![Page 10: Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient](https://reader030.vdocuments.us/reader030/viewer/2022032804/56649e425503460f94b35a66/html5/thumbnails/10.jpg)
Questions ?