In Silverlight, there are many different ways to access Web services and other networked resources. Typically there is a method for requesting data from a Web service that is best suited to the operation the application needs to perform.
HTTP Classes
You can access Web services or resources on a network server directly from a Silverlight-based application using the HttpWebRequest/HttpWebResponse or WebClient classes in the System.Net namespace. These classes provide the functionality required to send requests to any Web service available over the HTTP protocol. Silverlight does not support the ability to host HTTP-based services, so these classes are useful when the Silverlight client is using an existing Web service. Typically, you would use these classes if the HTTP service is hosted by a third-party and not within your control. In this case, you need to make sure the requests match the exact format expected by the service. However if you are building the service yourself, Silverlight offers more productive end-to-end solutions, which can be built using the Windows Communication Foundation (WCF) described in more detail in the next section. For more information about HTTP security restrictions and accessing Web services using the WebClient or HttpWebRequest/HttpWebResponseclasses, see HTTP Communication and Security with Silverlight.
WCF Services
WCF services provide the foundation for building Web services for a Silverlight client application. If you control the data and the server hosting the data, the easiest way to expose it to Silverlight is by using a WCF service.
Depending on what you are trying to build, WCF offers three top-level programming models that you can choose from. Each model has its strengths and weaknesses, and it is up to you to choose which model your application fits before building your service. The following illustration shows the WCF architecture layers and the programming models available when using them. For more information about the WCF architecture, see Introducing Windows Communication Foundation in .NET Framework 4.
.png)
WCF core services are the most flexible kind of WCF services. They allow you to expose a class as a service and exchange objects between Silverlight and that service. In the Silverlight application, you can use tools such as Visual Studio, to generate a local proxy class for the remote service. This enables you to access the service as though it is a local class. WCF core services support a breadth of protocols (including HTTP and TCP) and a variety of formats, such as SOAP, XML, and Atom. For more information, see Building and Accessing Services using Generated Proxies.
WCF Data Services
Windows Communication Foundation (WCF) Data Services, formerly known as ADO.NET Data services, provides a framework for you to access data from your existing data model in the style of representational state transfer (REST) resources. WCF Data Services exposes data as an Open Data Protocol (OData) feed. In addition, if your Silverlight application is interacting with SharePoint, SharePoint 2010 exposes data as WCF Data Services. WCF Data Services handles all of the HTTP communication, serialization, and other tasks you traditionally have when you attempt to expose your data model as a service. This means Silverlight-based applications can access this data through the standard HTTP protocol to execute queries, and even to create, update, and delete data in a data service, either in the same domain or cross domain. For more information, see WCF Data Services (Silverlight).
WCF RIA Services
WCF RIA Services simplifies the development of n-tier solutions for the enterprise. RIA Services provides data modeling, validation, concurrency, security and authentication tools and services that enable you to easily create forms that display data from the underlying database in the application style sometimes referred to as “forms over data”. In addition, since RIA Services exposes server data as WCF services, you can leverage the WCF configuration tools. For more information, see WCF RIA Services.
Sockets and Multicast
Silverlight offers support for sockets-based communication with classes in the System.Net.Sockets namespace. The classes provide a mechanism for real-time duplex communication with remote network resources and enables higher-level APIs to communicate over a bi-directional transport. This also allows an application to interoperate as a client with existing TCP services. For more information, see Working with Sockets. In addition, Silverlight 4 or later supports multicast messaging. Multicast messaging allows for a large receiver population and either a one-to-many or a many-to-many architecture. For more information see Working with Multicast.