Windows Phone Networks and Protocols

.World Wide Web

World Wide Web, Fair Use

Network Information

"Robust communications on a Windows Phone device includes the ability to switch between cellular and Wi-Fi connectivity and close connectivity when it best suits the apps running on the device."

  • The Microsoft.Phone.Net.NetworkInformation namespace provides classes for obtaining information about cellular and Wi-Fi networks:
    1. The DeviceNetworkInformation class provides networking information with the following static properties:
      • CellularMobileOperator - Gets the name of the cellular mobile operator.
      • IsCellularDataEnabled - Indicates whether the network is cellular data enabled.
      • IsCellularDataRoamingEnabled - Indicates whether the network allows data roaming.
      • IsNetworkAvailable - Indicates whether the network is available.
      • IsWiFiEnabled - Indicates whether the network is Wi-Fi enabled.
    2. The NetworkNotificationEventArgs class provides data to indicate network availability changes, such as a connection, disconnection, or configuration change.
      • The NetworkAvailabilityChanged event can be used to indicate when the status of a network interface changes. An application can register for this event and get a notification if a Wi-Fi network becomes available. The application could then adjust its behavior to take advantage of this high bandwidth network interface.
      • The Windows Phone Dev Center walks through an example of detecting network changes in the article How to detect network changes for Windows Phone.

Web Services

"A web service provides a standardized way for electronic devices to communicate over the World Wide Web."

  • Web services:
    • allow different applications from different sources to communicate without writing complex custom coding. Web Services can act like proxies between mobile apps and remote servers.
    • share business logic, data and processes between applications over the Web. Developers can add Web services to a Web page or an executable program to offer the shared functionality to users.
    • are NOT tied to any one operating system or programming language.
    • do NOT require the use of browsers or HTML.
  • Web service usage can be categorized as:
    1. Application Component - offers application functions such as calculators or language translation.

    2. Data Access - exchanges data between different applications on different platforms.
,Windows Communication Foundation Data Service Open Data Protocol

OData, Fair Use

Windows Communication Foundation

"Microsoft created Windows Communication Foundation as a way to bring together the functionality of their older communication technologies (ASMX, .NET Remoting, DCOM, MSMQ) under a unified programming model."

  • Windows Communication Foundation (WCF) can be used directly to create Web services and expose data, but it requires considerable effort. A simpler approach is to use one of the two later technologies that Microsoft has built on top of WCF (WCF Data Services or WCF RIA Services). WCF Data Services and WCF RIA Services are very different approaches for building data-oriented services.
    1. Windows Communication Foundation
      • Windows Communication Foundation (WCF) is a component of Microsoft's unified framework for building Web services and Web service clients.
        • Supports several patterns for sending data (request/reply, one-way, duplex-exchange).
        • Supports data encryption and can require user authentication. Security can be implemented using well-known standards such as SSL or WS-SecureConversation.
        • Supports multiple built-in transport protocols and encodings.
        • WCF is a runtime and a set of APIs for creating systems that send messages between services and clients. WCF can be used to make a class accessible as a service and then exchange objects between the app and the service.
        • Includes the use of Data Contracts which are agreements between a service and a client that describes complex data to be exchanged. The metadata in data contracts provides a way for the client and the service to understand complex data. If the service is using only simple types, there is no need to explicitly use data contracts.
    2. WCF Data Services
      • WCF Data Services is a resource-based API consisting of a thin layer over WCF and is based on the Open Data Protocol (OData).
      • WCF OData (formerly known as "ADO.NET Data Services") is a REST-based Web protocol for CRUD-style operations (Create, Read, Update and Delete) for interacting with a database.
        • OData is the web-based equivalent of ODBC, OLEDB, ADO.NET and JDBC.
        • OData is published by Microsoft under the Open Specification Promise so anyone can build servers, clients or tools without royalties or restrictions.
        • OData is built upon the Atom Publishing Protocol (AtomPub), which itself is built on top of the Atom Syndication Format (Atom).
        • OData provides a uniform way to to manipulate data using REST practices and JSON or ATOM syntax to discribe the payload. OData also provides a uniform way to represent metadata.
        • OData targets the Entity Framework. However, other data access layers are supported, but greater effort is required to use them.
        • The OData open source documentation OData V3 Documentation describes a typical OData interaction proceeds as follows:
          1. Client has an intent.
          2. Client asks for and parses the metadata document.
          3. Client uses metadata to determine how to form a request for its intent.
          4. Client performs request(s) to interact with data.
          5. Each response provides additional options to the client, in terms of both links and instance metadata.
          6. Client can follow links or combine instance metadata with service metadata to determine new entry points.

      • WCF RIA Services
        • WCF RIA Services is a domain-based API which simplifies the development of n-tier solutions for Rich Internet Applications (RIA).
          • WCF RIA Services was designed to work best with Silverlight, so typically it is more attractive for Silverlight clients than non-Silverlight clients.
          • You can build WCF RIA Services over any data access layer, including Entity Framework and LINQ to SQL.
          • The RIA Services framework makes the application logic on the server available to the RIA Services client without requiring duplication of the programming logic.
          • With a WCF RIA Services link established, Visual Studio continuously regenerates the client-side proxies to match the domain services on each build. It also auto-generates client-side copies of shared application logic defined in the services project.
    3. ,Rest and SOAP

      Rest and SOAP, Fair Use

      SOAP and REST

      "REST is popular for it's simplicity, performance, and support of multiple data formats. However, there are situations where SOAP is clearly the better choice, such as where transaction confirmation is required."

      • The two popular approaches for interfacing to the web with Web services are:
        1. SOAP - is a protocol which exclusively uses XML messaging technology and enables requests and responses to be made over any network transport protocol (typically HTTP). SOAP is synchronous, It has successful/retry logic built in and provides end-to-end reliability.

        2. REST - is an architectural style which provides a lighter weight alternative to SOAP by exploiting the existing technology and protocols of the Web. REST is asynchronous. It doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying.
      • Two major methods for providing Web services are SOAP and REST.
        • SOAP:
          • is a mature heavy-weight web protocol that has well-defined standards.
          • has additional overhead not found in the REST approach, but the overhead may contain advantageous functionality.
          • is a standard communication protocol (W3C Specification) that runs on top of a transport protocol (usually HTTP) that lets applications exchange XML-based messages.
          • only supports transferring data in XML format.
          • XML serialization is usually built in, where as with REST external libraries are required for data serialization.
          • supports additional enterprise security features and can provide a two-phase database commit.
          • frequently uses Web Services Description Language (WSDL) which is a sort of contract to define the interface.
          • is synchronous, It has successful/retry logic built in and provides end-to-end reliability.
        • REST:
          • is an acronymn for Representational State Transfer.
          • describes a set of architectural principles by which data can be transmitted over a standardized interface.
          • is associated with another term for REST-like web services which are called RESTful. RESTful web services are simple stateless APIs that exploit the existing technology and protocols of the Web.
          • uses the HTTP request methods (eg. GET, PUT, POST, or DELETE) and other existing features of the HTTP protocol.
          • is newer than SOAP and is growing in popularity.
          • is a much simplier method than SOAP.
          • supports many different data formats (XML, JSON, text, HTML, etc.).
          • has better performance and scalability.
          • is standard-less in terms of integration and implementation. However RESTful implementations can use Web standards like HTTP, XML, etc.
          • is asynchronous. It doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying.

      • REST is popular for it's simplicity, performance, and support of multiple data formats. However, there are situations where SOAP is clearly the better choice, such as where transaction confirmation is required. For example, during banking transactions. Retrying the banking transaction would be erroneous if the transaction succeeded the first time, but the response failed.

      • To generalize, REST works well when you have:
        • Limited Bandwidth and Resources
        • Stateless Operations

        and SOAP works well when you have:

        • A need for guaranteed reliability and security
        • Stateful Operations

      HTTP Web Service Classes

      "WebClient is built on top of HttpWebRequest/HttpWebResponse . It simplifies many common web service tasks resulting in less code."

      • The System.Net namespace contain the following classes which work with HTTP to provide the link between the app and a Web service. The classes retreive data using a Uniform Resource Identifier (URI). The classes use asynchronous communication.
        • HttpWebRequest and HttpWebResponse
          • These two classes work together. HttpWebRequest request the data/resource and HttpWebResponse provides a container for the incoming data from the server.
          • HttpWebRequest/HttpWebResponse enables more control over the Web service request than does the WebClient class.
        • WebClient
          • WebClient is a simplified alternative to HttpWebRequest/HttpWebResponse. WebClient both sends the request and receives the response from the server.
          • WebClient is built on top of HttpWebRequest/HttpWebResponse. It simplifies many common web service tasks resulting in less code.
          • WebClient is useful for quick-and-easy data retreival from a Web service.

      Computer Clip Art, Public Domain

      Multicast Communications

      "Multicasting is the sending of data over a network (eg the Internet) to many devices at one time."

      • The UdpAnySourceMulticastClient class enables devices to join a multicast group.
      • Multicasting is a type of broadcast, analogous to television signals.
      • Multicasting uses sockets to communicate using the User Datagram Protocol (UDP). UDP is a connection-less protocol which sends packets of data without establishing a connection between the sender and receiver. This makes UDP fast, but there is no guarantee of delivery. (Note: This is in contrast to Transmission Control Protocol (TCP) which is connection-oriented).
      • The IP addresses in the range of to are reserved for multicast communications.

      .World Wide Web

      Computer Clip Art, Public Domain

      Push Notifications

      "A communications channel must be established between the Windows Phone and the application that provides the push notification."

      • Push Notifications allow a Web service to send data to a Windows Phone. Windows Phone provides three types of push notifications:
        1. Toast Notifcations - are displayed at the top of the screen. Toast Notifications are usually a short text message.
        2. Tile Notifications - update the Live Tiles on the Windows Phone Start screen.
        3. Raw Notifications - allow custom data to be pushed to an application.
      • Toast and Tile notifications can occur when the associated app is NOT running.
      • Raw notifications require the associated app to be running.
      • The HttpNotificationChannel class is used to established a communication channel between the Windows Phone and the application that provides the push notification. To establish a communication channel use its properties:
        • ChannelName - name of the notification channel.
        • ChannelUri - source of current active notification channel.

        and methods:

        • BindToShellTile - binds the Tile with a notification subscription.
        • BindToShellToast - binds a toast notification subscription to the HttpNotificationChannel class instance.
        • Close - closes notification channel and disassociates all associated subscriptions.

      Reference Articles

      Additional SOAP and REST Resources: