WCF Service (WebService)
Web Services is a proven cross-firewall communication method, which is stable and widely recognized. In general, you need to specify the corresponding interfaces for the scattered crud operations and faithfully call them in Silverlight.
- Reasons for use: projects that require database interaction operations directly through services (weakening the business logic section ).
- To avoid this problem, you must always monitor data changes and call the corresponding service method for updates. Any concurrent operations or transactions become heavier and need to process a large numberCode.
ADO. NET data services
ADO. NET data services is a simple rest-based data communication method. It relies on HTTP to define service interfaces. For example, get operations are defined as read/write operations and post operations are defined as updates. It uses atom or JSON as the serialization format, so it can be called by various types of clients.
It converts the URI-based API into a LINQ call to provide insert, update, delete, and other operations. This means that ADO. Net itself is a thin layer, which aims to translate the URI model into data communication code.
For Silverlight, the real highlight of ADO. NET data services is its client class library. This client class library allows developers to use LINQ query on the client and execute it on the server. Of course, the supported LINQ syntax has some limitations compared to the server, which covers about 80% of the scenarios. Of course, ADO. NET data service also allows developers to customize the remaining operations when necessary to adapt to other scenarios. In addition, the client Class Library provides a powerful data context class to monitor and process batch operations with transaction support.
Using ADO. NET data services to publish data communication is actually an alternative to defining interfaces in the form of public query endpoints, which is the most special place. For example, we can use
// Silverlight code // Use LINQ to create a towel VaR qry = (from G in DS. Games Where G. Price <50 m Orderby G. Name Select g) as dataservicequery <game>; // Execute the query Qry. beginexecute (New asynccallback (r => { Games2.itemssource = qry. endexecute (R). tolist (); Games2.displaymemberpath = "name "; }), Null ); |
- Reason for use: A simple and secure model allows developers to define the queries they need in code (relative to the interface-based WCF Service ). Thanks to the LINQ call and context classes, using the ADO. Net Data Services Client class library will reduce the amount of your client code.
- Avoid using ADO. NET data services when you want to strictly control the data access interface and do not want the producer to directly use the LINQ query on the client.
WCF Ria services
Ria services is based on the idea that a data communication API is created on the server and client code is generated in Silverlight. It focuses on sharing code between the server and the client (including the verification logic ). In addition, he allows developers to create a series of interfaces, and also provides context objects on the client to monitor data (including Batch operations) changes and feedback to the server. To some extent, Ria services is a set of web services and ADO. NET data.
As Ria services is defined based on the query interface of the server, the client developers can call the query defined by their interface as follows:
// Silverlight code // Context object monitoring data changes Xboxgamescontext CTX = new xboxgamescontext (); // Ria query, based on the Interface VaR qry = CTX. getgamesbygenrequery ("Shooter "); // Bind data TheList. itemssource = CTX. Load <game> (qry). allentities; |
When introducing ADO. NET data services, it was mentioned that developers can use LINQ to query. Ria services also allow adding a LINQ constraint to the query endpoint. For example, you can add a LINQ expression to the endpoint as follows:
VaR riaqry = CTX. getgamesquery () . Where (G => G. Price <50 m) . Orderby (G => G. Name ); Loadoperation <game> op = CTX. Load <game> (riaqry ); |
- Reason for use: RIA services can effectively reduce applicationsProgramNumber of layers, especially for application development scenarios that require rapid response. The RIA Service also provides interface-based support like WebService and support for LINQ-based queries like ADO. NET data services.
- To avoid this problem, Ria Services uses a lot of automatically generated code, which may cause trouble during debugging.
So what is your choice? Welcome to the discussion ~