无法使用 WCF Ria 中域服务类的方法? [英] Unable to use methods from Domain Service class in WCF Ria?

查看:23
本文介绍了无法使用 WCF Ria 中域服务类的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个 Silverlight 应用程序,它在文本框中获取用户的名字、姓氏、密码、电子邮件地址,然后将这些添加到数据库中.

I am trying to build an silverlight application which takes user first name, last name, pass, email address in text boxes and then add these to the database.

为此,我使用 WCF Ria Services.

我遵循的步骤是:

在我的项目(在 Web 部件中)添加了 ADO.NET 实体数据模型,然后添加了 Domain Service class.

Added ADO.NET Entity Data Model and then Domain Service class in my project (in web part).

现在我在我的 DomainService 类中有一些预定义的方法,如插入、更新方法.我知道如何在 DataGrid 中显示数据,但这不是我想要的.

Now i have got some predefined methods in my DomainService Class like Insert, Update methods. I know how to show data in DataGrid but its not what i want.

我想要的是为以下所有内容定制:

What i want is to customize all this for :

当用户点击提交按钮时,里面应该有类似 AddInfo(all parameters) 的方法,它可以将所有数据添加到我的 sql server 数据库 {at present LocalHost}.

When user clicks the submit button then there should be method inside this like AddInfo(all parameters) which can add all the data to my sql server database {at present LocalHost}.

简单地说通过自定义方法访问数据库,使用 WCF Ria 服务在 sql server 中添加数据

我知道在 .net 表单中工作时非常简单.但是 Silverlight & 怎么样?WCF 里亚?

I know it was very simple while working in .net forms and all. But how about Silverlight & WCF ria ?

请提出建议.

推荐答案

简单地说就是通过自定义方法访问您的数据库以添加使用 WCF Ria 服务在 sql server 中的数据

In simple words accessing your database through custom methods to add data in sql server using WCF Ria Services

您应该做的是在服务器端编写自定义方法.

What you should do is write a custom method in server-side.

在服务器端,您有一个 DomainService 类应该从 LinqToEntitiesDomainService.

On server-side, you have a DomainService class that should inherit from LinqToEntitiesDomainService<TContext>.

只需在这个类中添加一个带有Invoke属性的方法,例如:

Simply add a method in this class with the Invoke attribute, for example:

[Invoke]
public void AddNewUser(string name, string firstName, int age)
{
    // Put logic here to add the user to the DB
}

将用户添加到数据库的逻辑非常简单,只需创建一个新的Entity,将其添加到上下文中并调用context.SubmitChanges();

The logic to add a user to the database is really simple, just create a new Entity, add it to the context and call context.SubmitChanges();

当您编译客户端 RIA 服务项目时,与您的 DomainService 对应的自动生成的代理类将包含您的新方法,您将能够使用以下方法调用它:

When you compile the client RIA Services project, the auto-generated proxy class that correspond to your DomainService will contain your new method, and you'll be able to call it using:

yourDomainContext ctx = new yourDomainContext();
ctx.AddNewUser("dsd", "ds", 42).Completed += (sender, e) =>
{
     // Called asynchronously when the job is done
};

这篇关于无法使用 WCF Ria 中域服务类的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆