Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Services Rob S. Miles | Microsoft MVP | University of Hull, UK Andy Wigley | Microsoft MVP | Appa Mundi Session 11.0.

Similar presentations


Presentation on theme: "Web Services Rob S. Miles | Microsoft MVP | University of Hull, UK Andy Wigley | Microsoft MVP | Appa Mundi Session 11.0."— Presentation transcript:

1 Web Services Rob S. Miles | Microsoft MVP | University of Hull, UK Andy Wigley | Microsoft MVP | Appa Mundi Session 11.0

2 Windows Phone Agenda Networking for Windows Phone WebClient HttpWebRequest Sockets OData Wire Serialization

3 Networking on Windows Phone

4 Windows Phone Networking on Windows Phone Support for networking features – Windows Communication Foundation (WCF) – HttpWebRequest – WebClient (no cross-domain policy file required) – Sockets Not supported in this version – Custom WCF Bindings – WCF RIA Services – NTLM authentication 4

5 Windows Phone WebClient Simple API for HTTP requests In Windows Phone 7.0, ran on the UI thread – Block UI operations – Avoid! In Windows Phone 7.5 – Completely reworked – Now operates on originating thread

6 Windows Phone Simple Http Operations – WebClient

7 Demo Simple HTTP Networking with WebClient 7

8 Windows Phone More Control - HttpWebRequest

9 Demo HttpWebRequest 9

10 Sockets

11 Sockets Support in Windows Phone OS 7.1  TCP  Connection-oriented  Reliable Communication  UDP Unicast, UDP Multicast  Connectionless  Not Reliable  IPV4 supported e.g. 172.36.254.14  No IPV6 support

12 Demo Sockets 12

13 WCF/ASMX Services  Can ‘Add Reference’ from Windows Phone projects to automatically generate proxy classes  ASMX should ‘just work’  WCF requires that you use basicHttpBinding 13

14 RESTful Web Services Building them  Rather than building “walled gardens,” data should be published in a way that allows it to reach the broadest range of mobile clients  Old-style ASMX SOAP 1.1 Web Services using ASP.NET or Windows Communication Foundation (WCF) require clients to implement SOAP protocol  With Windows Phone 7 and Silverlight, we use WCF with BasicHttpBinding both on-premise and as a Web Role in Windows Azure to publish our data from local and cloud-based data sources like SQL Azure  Recommend using lightweight REST + JSON Web Services that are better optimized for high-latency, slow, intermittent wireless data connections 14

15 WCF Data Services: OData  WCF Data Services provide an extensible tool for publishing data using a REST-based interface  Publishes and consumes data using the OData web protocol (http://www.odata.org)http://www.odata.org  Formatted in XML or JSON  OData Client Library (DataServicesClient) now included in Windows Phone OS 7.1 SDK Default Genres Titles …

16 Generate Client Proxy  In most cases, Add Service Reference will just work  Alternatively, open a command prompt as administrator and navigate to %windir%\Microsoft.NET\Framework\v4.0.30128  Run this command DataSvcutil.exe /uri:http://odata.netflix.com/Catalog/ /DataServiceCollection /Version:2.0/out:netflixClientTypeshttp://odata.netflix.com/Catalog/  Add generated file to your project

17 Fetching Data 17

18 OData Services 18 Demo

19 Network Awareness Making Decisions based on Data Connections  Mobile apps shouldn’t diminish the user experience by trying to send or receive data in the absence of network connectivity  Mobile apps should be intelligent about performing heavy data transfers or lightweight remote method calls only when the appropriate data connection is available  With Windows Phone 7 and Silverlight, we use the NetworkInterfaceType object to detect network type and speed and the NetworkChange object to fire events when the network state changes 19

20 NetworkInformation in 7.1  All in Microsoft.Phone.Net.NetworkInformation namespace  Determine the Network Operator:  DeviceNetworkInformation.CellularMobileOperator  Determine the Network Capabilities:  DeviceNetworkInformation.IsNetworkAvailable  DeviceNetworkInformation.IsCellularDataEnabled  DeviceNetworkInformation.IsCellularDataRoamingEnabled  DeviceNetworkInformation.IsWiFiEnabled  Get Connection Information about a socket:  NetworkInterfaceInfo netInterfaceInfo = socket.GetCurrentNetworkInterface();  Set preferred network interface for a socket  socket.SetNetworkPreference( NetworkSelectionCharacteristics.Cellular);

21 Wire Serialization  Mobile devices are often connected to poor quality network connections  Best chance of success in network data transfers achieved by  Keep data volumes as small as possible  Use the most compact data serialization available  Avoid large data transfers  Avoid transferring redundant data  Design your protocol to only transfer precisely the data you need and no more

22 Wire Serialization 22 Demo

23 Wire Serialization Affects Payroll Size  Simple test case: Download 30 data records  Each record just 12 fields  Measured bytes to transfer Wire Serialization Format Size in Bytes ASMX SOAP – DataSet (XML) 39670 ODATA XML73786 ODATA JSON34030 REST + JSON15540 REST + JSON GZip8680

24 Windows Azure and Windows Phone

25 User Authentication Store Image in Windows Azure Blob Storage Process ImageSend Notification

26 Windows Azure Toolkits for Devices Make it easier for phone developers to use Windows Azure WP7 – http://watoolkitwp7.codeplex.com http://watoolkitwp7.codeplex.com iOS - https://github.com/microsoft-dpehttps://github.com/microsoft-dpe Android (coming soon) Toolkits include: Native libraries (e.g..NET, Objective-C) Samples Project templates Documentation

27 Summary  Windows Phone has a sockets API to support connection- oriented and connectionless TCP/IP and UDP/IP networking  Support for ASMX, WCF and REST Web Services  DataServicesClient for OData service access out of the box in 7.1 SDK  Consider JSON serialization for maximum data transfer efficiency  Windows Azure Toolkit for Windows Phone eases interaction with Windows Azure

28 The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. © 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.


Download ppt "Web Services Rob S. Miles | Microsoft MVP | University of Hull, UK Andy Wigley | Microsoft MVP | Appa Mundi Session 11.0."

Similar presentations


Ads by Google