将 Silverlight4 应用程序与 ASP.NET 应用程序集成
我在silverlight4中制作了一个应用程序,并使用EDM和WCF-RIA进行数据库访问。
现在我想将此应用程序集成到 ASP.net 项目中,当我将其集成到 ASP.net 项目中时,它给出了此异常 -
Microsoft JScript 运行时错误:Silverlight 应用程序加载操作中的未处理错误查询“GetQuestions”失败。远程服务器返回错误:NotFound。在System.ServiceModel.DomainServices.Client.OperationBase.Complete(异常错误) 在System.ServiceModel.DomainServices.Client.LoadOperation.Complete(异常错误) 在 System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult) 在 System.ServiceModel.DomainServices.Client.DomainContext.<>c_DisplayClass1b.b_17(Object )
所以请帮助我。
I made one application in silverlight4 and used EDM and WCF-RIA for database access.
Now I want to integrate this application to asp.net project and when I integrate it into the ASP.net project it is giving this exception-
Microsoft JScript runtime error: Unhandled Error in Silverlight Application Load operation failed for query 'GetQuestions'. The remote server returned an error: NotFound. at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
at System.ServiceModel.DomainServices.Client.DomainContext.<>c_DisplayClass1b.b_17(Object )
so please help me anybody.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 RIA 服务 DomainService 有 2 个部分。您通过复制 XAP 文件复制了客户端部分,但缺少服务的 RIA WCF 服务器端部分。
您需要将域服务文件从原始 Silverlight 网站移动到新的 ASP.Net 项目(以及正确连接它所需的任何 web.config 设置)。 这不在 ASPX 文件中。如果没有看到现有项目的具体信息,我无法准确地告诉您需要迁移哪些文件名。
我的建议是始终创建 RIA 服务库,而不是直接添加到 Silverlight 应用程序。然后您可以将客户端库链接到任意数量的 Silverlight 应用程序,然后将 RIA 库的 .Web 部分链接到您的网站以提供 WCF 服务。同样,关键是迁移配置设置。
如果您创建一个新的 RIA 服务库项目,添加您的 EDM 等,然后将这两部分链接到单独的 Silverlight 应用程序和新的 ASP.net 网站,这可能会更有意义。
分步操作:
RiaServices.web
项目。选择添加新项目。选择左侧的数据。选择右侧的ADO.Net 实体数据模型。在本例中,我假设它被称为默认的Model1.edmx
。将其连接到您的数据库表等。RiaServices.web
项目中创建引用 EDMX 模型的域服务。选择添加新项目。选择左侧的Web。选择右侧的域服务类。在本例中,我假设它名为DomainService1.cs
。通过勾选复选框,从添加新域服务类弹出窗口中选择您的数据项。将为您选择的每个项目创建一组 RIA 服务对象和方法。直接从 Silverlight 代码使用
RIAServicesLibrary1
客户端对象(在本示例中称为 DomainService1),如下所示:DomainService1 client = new DomainService1();
或使用
数据源
窗口将新网格等拖/放到页面上。如果
数据源
窗口不可见,请选择“数据”菜单,然后选择“显示数据源”选项。有关详细信息,请尝试此 Microsoft 链接:使用 WCF RIA 服务
Your RIA Services DomainService has 2 parts. You have copied the client part by virtue of copying the XAP file, but you are missing the RIA WCF server-side part of the service.
You need to move the Domain service files from your original Silverlight website to your new ASP.Net project (along with any web.config settings required to wire it up properly). This is not in the ASPX files. Without seeing the specifics of your existing projects I can't tell you exactly what filenames you need to migrate.
My suggestion is to always create RIA Service libraries instead of adding directly to a Silverlight application. Then you can link the Client-side library to any number of Silverlight applications, then link the .Web part of the RIA library to your website to provide the WCF service. Again the key is to migrate the config settings.
It will probably make a lot more sense if you create a new RIA services library project, add your EDM etc, then link the halves to a separate Silverlight app and your new ASP.net website.
Step-by-step:
RiaServices.web
project. Select Add new item. Select Data on the left. Select ADO.Net Entity Data Model on the right. I will assume it is called the defaultModel1.edmx
for this example. Connect it to your database tables etc.RiaServices.web
project. Select Add new item. Select Web on the left. Select Domain Service Class on the right. I will assume it is calledDomainService1.cs
for this example. Choose your data items from the Add New Domain Service Class popup window by ticking the checkboxes. A set of RIA services objects and methods will be created for each item you select.Use the
RIAServicesLibrary1
client object (called DomainService1 in this example) directly from your Silverlight code like this:DomainService1 client = new DomainService1();
or use the
Data Sources
window to drag/drop a new grid etc onto a page.If the
Data Sources
window is not visible select the "Data" menu then the "Show Data Sources" option.For more information try this Microsoft link: Using WCF RIA Services