Top Banner
Silverlight, RIA & Interop Les communications en Silverlight Stève Sfartz Architecte Microsoft France http://blog.sfartz.com http://blogs.msdn.com/ssfartz http://blogs.msdn.com/cloud_computing http://blogs.msdn.com/silverlight_plus_java
10

Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient.

Dec 27, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Questions ?