Use the Silverlight Ria services Class Library

Source: Internet
Author: User
Use the Silverlight Ria services Class Library

In the previous Microsoft SL promotion, the use of another "Silverlight up on your web" ad is a bit overbearing. A developer who has worked on the MVC framework should feel that this is a bit like the MVC display layer framework. the page is relatively clean. the output style is similar. however, I have only a preliminary understanding of the structure of this template. this information is rare. go to Silverlight Ria services Class Library.

 

A: Silverlight Ria services Class Library

It mainly allows you to create reusable middle layers and presentation layer logic. however, it is more difficult to create an RIA service solution than to create an RIA service solution. when we create a common Silverlight application. if enable WCF Ria service. this option establishes an RIA service link association with the server project through the Silverlight client. the Silverlight Ria services Class Library separates this default Ria service link association. separate this relationship. it is roughly as follows:

B: Create the Silverlight Ria services Class Library

Create a common Silverlight application project. note that the Silverlight Ria services class library is used to isolate the RIA service link relationship. therefore, if the Enable WCF Ria service option is not selected, the RIA service is not enabled during creation.

After the project is created, add the Silverlight Ria services class library project to the solution to complete the solution project structure:

There are two more projects in the hroaservicelibdate Folder: hroaservicelibdate and hroaservicelibdate. Web. Since a class library is used to create a RIS service link association, you need to add project references. reference sequence and rules:

We can see that the association between the RIA service link is established, and the reference shows that it is relative:

Testcreateservicelib. The web references hroaservicelibdate. Web.

Testcreateservicelib references hroaservicedate in the class library.

The RIA service link association is established to complete the rewriting and generation solution. when we separate this layer of relationship. the original encoding habits also change. previously, the data entity and domain service accessed by data were stored in the Server Client testcreateservicelib. in the WEB Project. now you can put it in the class library hroaservicelibdate. in the WEB Project. now hroaservicelibdate. add a workbill entity to the Web to access [one entity and one domain service]. rewrite compilation Solution
To view all files:

The original generated_code folder is transferred from the original default testcreateservicelib project to hroaservicedate. as a result, you can see that the transfer of the generated_code folder is synchronized with the RIA service link. although no code is generated for the testcreateservicelib project, a reference relationship is established between the hroaservicedate and testcreateservicelib project. you can still use the code generated by testcreateservicelib.

C: access data as a Class Library:

Add System in testcreateservicelib. servicemodel. domainservices. client Reference [not added by default]. [program files] \ microsoft sdks \ Ria Services \ V1.0 \ libraries \ Silverlight can be found in the SDK directory by default.

Drag a DataGrid Control in the mainpage. XAML file to test the data access. The layout is as follows:

1 <grid X: Name = "layoutroot" background = "orange">
2 <SDK: DataGrid autogeneratecolumns = "false" Height = "212" horizontalalignment = "Left" margin =, 522 "name =" datagrid1 "verticalignment =" TOP "width =" ">
3 <SDK: DataGrid. Columns>
4 <SDK: Maid header = "code" binding = "{binding code}"> </SDK: Maid>
5 <SDK: Maid header = "Creation Time" binding = "{binding createdate}"> </SDK: Maid>
6 </SDK: DataGrid. Columns>
7 </SDK: DataGrid>
8 </GRID>

Backend code:

Code
1 // Add reference
2 using hroaservicelibdate. Web; // note that when referencing, the web project in the RIA service class library is not testcreateservicelib. Web
3 using system. servicemodel. domainservices. client;
4
5 namespace testcreateservicelib
6 {
7 public partial class mainpage: usercontrol
8 {
9 // statement
10 private hroaservicelibdate. Web. hroamodeldomaincontext getcontent = new hroamodeldomaincontext ();
11 Public mainpage ()
12 {
13 initializecomponent ();
14 // obtain and bind data
15 loadoperation 16 this. Maid = getproductlist. entities;
17}
18}
19}

If the code is rewritten to generate and run directly, A getproductorderquery () error is prompted when the getproductorder not found object cannot be found:

This is because the link information of the domain Service database is read in testcreateservicelib by running Silverlight on the web. web project web. config does not exist. in the hroaservicelibdate. WEB Project app. the Config File copies the object and database link configuration information to the Web. config. the copied content is. <connectionstrings>, <system. servicemodel>, and

Data retrieved successfully.

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.