ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:445.78KB ,
资源ID:19385930      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/19385930.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Silverlight tutorial Creating a data centric web app with DataGrid LINQ and WCF Web ServiceWord文档下载推荐.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Silverlight tutorial Creating a data centric web app with DataGrid LINQ and WCF Web ServiceWord文档下载推荐.docx

1、7. Drag DataTable onto DataClasses1.dbml 8. Set key as the primary key 9. View properties for DataClasses1.dml. Set the serialization mode to unidirectional so that it is compatible with web services. 10. Okay, that takes care of your database. Now lets set up the web service. Right click on the Wcf

2、SqlDemoWeb project and add a new item. Select the Silverlight-enabled WCF Service template and name it DemoService.svc 11. Delete DoWork method and replace with the two methods below plus the following using references. By the way, the “var selected_rows = from rows in db.DemoTables select rows” stu

3、ff, thats LINQ. Its fantastic. Its a very clean sensible query language that is built into .NET 3.5 that can be used for querying databases, XML, and even collections. One of the easier ways to figure out what link is, is to look at some examples. I recommend Microsofts 101 LINQ Samples . The LINQ l

4、ine that I use in the GetRows method loosely means “Take the table db.DemoTable and assign the elements of that table to the collection rows then select all those rows and assign them to the collection selected rows”. Collapse Copy Code using System.Collections.Generic;using System.Text;and also / R

5、eturn the list of valid dataOperationContractpublic List GetRows()DataClasses1DataContext db = new DataClasses1DataContext();var selected_rows = from rows in db.DemoTables select rows;return selected_rows.ToList();/ Insert a new data into the databasepublic void InsertData(string testItem1,string te

6、stItem2)/ Create a new row object.DemoTable row = new DemoTableKey = Guid.NewGuid(),TestItem1 = testItem1,TestItem2 = testItem2;/ Add the new object to the collection.db.DemoTables.InsertOnSubmit(row);/ Submit the change to the database.db.SubmitChanges();12. Now we need to let our Silverlight clien

7、t know about the web service weve just created. Right click SilverlightClient and select Add Service Reference. Click Discover. VS2008 should find the service from the project. Allow it to be saved in the namespace ServiceReference1. 13. Open page.xaml in ExpressionBlend. Make a form that looks some

8、thing like what Ive created below. Name the text boxes TestItem1TxtBoxand TestItem2TxtBox 14. Now lets add the datagrid into which the data we retrieve from the web service will be placed. The Datagrid control is not a default control of your Silverlight project, so youll have to add it. Right click

9、 on references in SilverlightClient and add a reference to System.Windows.Control.Data. Go to page.xaml. Add the following attribute to the user control element so we can get access to the DataGrid xmlns:my=clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data15. Now you can go

10、 to the asset library and find DataGrid under Custom Controls. 16. Add a DataGrid to the project and size it. Name the grid ResultsGrid. If you look at the XAML it should look similar to the below. 17. Add a button and label it “Get”. The end result should be something like as follows: 18. Add OnGet

11、BtnClicked and OnSubmitBtnClicked to the clicked events of the respective buttons in Expression Blend. This will add the attributes to the XAML button tags and will wake up VS2008 and add the specified methods to the code behind file. 19. Fill in the OnSubmitBtnClick and OnGetBtnClick as shown below

12、. Create a call back to handle the GetRowsCompleted event. (By the way, are you noticing how easy this is? Look at how much is getting done with a few lines of code and look how clean and sensible these few lines are.) private void OnGetBtnClick(object sender, RoutedEventArgs e)DemoServiceClient web

13、Service = new DemoServiceClient();webService.GetRowsCompleted +=new EventHandler(webService_GetRowsCompleted);webService.GetRowsAsync();void webService_GetRowsCompleted(object sender, GetRowsCompletedEventArgs e)ResultsGrid.ItemsSource = e.Result;private void OnSubmitBtnClick(object sender, RoutedEv

14、entArgs e)webService.InsertDataAsync(TestItem1TxtBox.Text, TestItem2TxtBox.Text);20. Build and test. Try submitting a few items and then getting the results. You should see something like the following:21. Easy right? Notice how we didnt even have to do anything to get the DataGrid to display our re

15、sults other than assign our results to the DataGrids ItemsSource. The only down side to this simplicity is that were seeing everything returned including the guid representing the key. Thats not very user friendly. Lets get rid of the auto-generation of columns and create custom ones. Also it seems

16、I needed to add an explicit size to the DataGrid or Id get a funny rendering of the grid when its empty. datagrid margin=8,283,51,85 autogeneratecolumns=False x:name=width=641 height=232DataGridTextColumnHeader=Test Item 1DisplayMemberBinding=Binding TestItem1Test Item 2Binding TestItem2/my:datagrid

17、22. Build and debug. The results should look exactly like before, except this time no column for Key. 23. By now youre probably collecting some garbage in your database, because we have no way to delete any items. Lets change that now. First lets modify our web service to be able to delete items fro

18、m our database. Add the following to DemoService. Note that were using more LINQ. The line below written in LINQ loosely means “Take the table db.DemoTable and assign the elements of that table to the collection rows then select those rows where the key is the passed guid and assign those selected r

19、ows to the collection selectedrow”. / Delete the item specified by the passed keypublic void DeleteRow(Guid key)var selected_row = from rows in db.DemoTables where rows.Key=key select rows;/ Delete the selected rows. There will actual be only one/ item in this collection because the Guid is unique a

20、nd is the/ primary key for the table.db.DemoTables.DeleteAllOnSubmit(selected_row);24. Add a delete button. When the delete button is clicked will delete whatever item in our DataGrid that was selected. private void OnDeleteClick(object sender, RoutedEventArgs e)DemoTable selectedRow = ResultsGrid.S

21、electedItem as DemoTable;/ Now access the service to delete the itemwebService.DeleteRowAsync(selectedRow.Key);/ Now refresh the grid25. Rebuild and Debug. Now you can select items and delete them. Tutorial Part 2: Deploying the web app to a remote server25. 1. Publishing the application to the web

22、can be a little difficult. The instructions below have been tried out on my web hosting provider , but youre likely to need to do something similar for other host providers as well. 2. To see the difficulty, publish the website. Now DemoService is located at your server right? All you might think yo

23、u need to do is reconfigure your silverlight client to reference the service at your website. Go ahead and try it. Right click on ServiceReference1 and select Configure service reference. Add the address of the service. In my case it is Youll get the error below and you wont be able to proceed. 3. Heres the work around. Were going to override the way the server creates the Service Host. Add the following class to DemoService.svc.cs public class MyServiceHostFactory : ServiceHostFactory protected override ServiceHost Create

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1