Académique Documents
Professionnel Documents
Culture Documents
50:00
50:00 60:00 50:00 25:00 25:00 30:00
50:00
35:00
35:00 25:00 25:00 60:00 50:00 50:00
50:00
50:00
Module Agenda
Networking for Windows Phone WebClient HttpWebRequest Sockets
supported in Windows.Networking.Sockets
NTLM and Kerberos authentication support Incoming Sockets
WP7.1
WP8
W8
UploadStringTaskAsync() etc
HttpWebRequest.GetResponseAsync() These methods are not supported on Windows Phone 8
You must use the correct host name or raw IP address of your host PC in URIs
Save changes
Use Add Existing Website to add the website folder back into your solution
Useful References | How to: Specify a Port for the Development Server http://msdn.microsoft.com/en-us/library/ms178109(v=VS.100).aspx
WebClient
HttpWebRequest is a lower level API that allows access to the request and response streams That state object passed in the BeginGetResponse call must be the initiating HttpWebREquest object or a custom state object containing the HttpWebRequest
Demo 2: HttpWebRequest
Sockets
Web Services
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
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
protocol (http://www.odata.org)
Formatted in XML or JSON
Fetching Data
public partial class NorthwindModel { NorthwindEntities context; private DataServiceCollection<Customer> customers;
private override void LoadData() { context = new NorthwindEntities(new Uri("http://services.odata.org/V3/Northwind/Northwind.svc/")); // Initialize the context and the binding collection customers = new DataServiceCollection<Customer>(context); // Define a LINQ query that returns all customers. var query = from cust in context.Customers select cust; // Register for the LoadCompleted event. customers.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(customers_LoadCompleted); // Load the customers feed by executing the LINQ query. customers.LoadAsync(query);
} ...
Network Awareness
Making Decisions based on Data Connections Mobile apps shouldnt 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, we use the NetworkInterfaceType object to detect network type and speed and the NetworkChange object to fire events when the network state changes
39
Size in Bytes
8680
Reference: http://blogs.msdn.com/b/astoriateam/archive/2011/10/04/odata-compression-in-windows-phone-7-5-mango.aspx
Demo 5: Compression
48
Data Sense
ConnectionCost
Examples
Stream high-definition video. Download high-resolution pictures. Retrieve email attachments. Stream high-definition video. Download high-resolution pictures. Retrieve email attachments. Stream lower-quality video. Download low-resolution pictures. Retrieve only email headers. Postpone tasks that transfer data. Stop downloading video. Stop downloading pictures. Do not retrieve email. Postpone tasks that transfer data.
Unrestricted
Not applicable.
All three of the following properties are false. ApproachingDataLimit OverDataLimit Roaming ApproachingDataLimit is true, when NetworkCostType is Fixed or Variable. Not applicable when NetworkCostType is Unknown. OverDataLimit or Roaming is true
No restrictions.
Fixed or Variable
No restrictions.
Fixed or Variable
Network Security
You can install a self-signed cert into the Windows Phone Certificate Store
Expose the .cer file on a share or website protected by authentication Alllows you to access private servers secured by a self-signed server certificate
Authentication
As well as encrypting data in transit, you also need to authenticate the client to make sure they are allowed to access the requested resource For communications over the Internet, secure web services using Basic HTTP authentication Transfers the username and password from client to server in clear text, so this must be used in conjunction with SSL encryption For Intranet web services, you can secure them using Windows or Digest authentication Windows Phone 8 supports NTLM and Kerberos authentication
Provide your own UI to request the credentials from the user If you store the credentials, encrypt them using the ProtectedData class
// Create a file in the application's isolated storage. IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication(); IsolatedStorageFileStream writestream = new IsolatedStorageFileStream(FilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write, file);
// Write data to the file. Stream writer = new StreamWriter(writestream).BaseStream; writer.Write(protectedSecretByte, 0, protectedSecretByte.Length); writer.Close(); writestream.Close(); }
// Decrypt the data by using the Unprotect method. byte[] clearTextBytes = ProtectedData.Unprotect(encryptedDataArray, null);
// Convert the byte array to string. string data = Encoding.UTF8.GetString(clearTextBytes, 0, clearTextBytes.Length);
Live SDK
Windows Live SDK Makes it easy to use SkyDrive in your Windows Phone and Windows 8 apps Live SDK also available for iOS and Android Store data in the cloud in the Microsoft Account users SkyDrive Restriction on acceptable file types now removed! Share data between Windows 8 and mobile device apps http://msdn.microsoft.com/en-us/live/default.aspx
Summary
WebClient and HttpWebRequest for HTTP communications 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 Consider JSON serialization for maximum data transfer efficiency Windows Phone 8 supports Basic, NTLM, digest and Kerberos authentication Encrypt sensitive data on the phone using the ProtectedData class Live SDK and Windows Azure Mobile Services ease integration with the cloud
The information herein is for informational purposes only an 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.
2012 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.