Handling Methods and examples of client and server of WCF Ria services

Source: Internet
Author: User
Silverlight Client Access

1. First, the project is linked to the server project. The build server project is generated under the generated_code of the client project and other directories.Code

2. Use code or XAML (domaindatasource) to access the service

 
Xmlns: domain = "CLR-namespace: Ria. Web. Services"
Title = "demo page" style = "{staticresource pagestyle }"

Xmlns: SDK = "http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns: riacontrols = "CLR-namespace: system. Windows. controls; Assembly = system. Windows. Controls. domainservices">
<Grid X: Name = "layoutroot">
<Grid. rowdefinitions>
<Rowdefinition/>
<Rowdefinition/>
</Grid. rowdefinitions>
<Riacontrols: domaindatasource name = "datasource" autoload = "true"
Queryname = "getcustomers">
<Riacontrols: domaindatasource. domaincontext>
<Domain: northwindcontext/>
</Riacontrols: domaindatasource. domaincontext>
</Riacontrols: domaindatasource>
<SDK: DataGrid name = "datagrid1" grid. Row = "0" itemssource = "{binding elementname = datasource, Path = data}"/>
<SDK: DataGrid name = "datagrid2" grid. Row = "1"/>
</GRID>

Northwindcontext context = new northwindcontext ();
Entityquery <customer> query = context. getcustomersquery ();
/// Load all
// Context. Load <customer> (query );
// This. Maid = context. MERs MERS;
VaR q = from C in query where c. City = "London" orderby C. customerid select C;
Context. Load <customer> (Q );
This. Maid = context. MERs MERS;

View the HTTP protocol and you will see the following requests sent to the server:

GET/clientbin/RIA-Web-Services-NorthWindService.svc/binary/getcustomers

GET/clientbin/ RIA-Web-Services-NorthWindService.svc/binary/getcustomers? $ Where = (it. City % 253d % 253d % 2522 London % 2522) & $ orderby = it. customerid HTTP/1.1

The method is basically the same as that of the WCF data service.

Note: domaindatasource is included in the system. Windows. Controls. domainservices component.

Server domain service method

The methods in the server service class follow the following conventions:

Method prefix

Annotation Property

Description

(Any)

[Query ()]

A method that returns data without any side effects. the usual approach is to prefix with get, but any prefix is fine as long as the function returns an instance of an entity T, an ienumerable <t>, or an iqueryable <t>.

Insert, add, create

[Insert ()]

An operation that inserts a single entity into the data store. The method takes the entity as a parameter.

Update, change,

Modify

[Update ()]

An operation that updates a single entity in the data store. The method takes the entity as a parameter.

Delete, remove

[Delete ()]

An operation that deletes an entity in the data store. The method takes the entity as a parameter.

(Any)

[Invoke ()]

A business method that must be executed without tracking or deferred execution. It may or may not have side effects. Use only when one of the other method types can't be used.

(Any)

[Update (usingcustommethod = true)]

Mark usingcustommethod = true to perform specific update operations, such as cascade update manually.

The parameter is an object class. When submitchanges is called, this function to update the object is automatically called.

-

[Ignore ()]

Methods, such as updateemployee, do not generate client columns.

The above descriptions are all methods that can be written in the server class. In this class, you can perform various operations such as business logic verification and processing, data update, and so on.

Example

Ria. Web project on http://dskit.codeplex.com

The running effect is as follows:

Includes the data list display, data editing, and domain service methods, including:

Use of domaindatasource: filtering, paging, sorting, grouping, etc.

Use dataform and domaindatasource to add, delete, and modify data.

Manually call the server Method

In sliverlight, The mvvp mode can be used for more explicit layering of large applications.

note: the code used to call the server in sliverlight is asynchronous in many cases. [The specific cause is related to the browser. For details, refer to msdn]. therefore, pay attention to the results returned by using the method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.