Unable to use methods from Domain Service class in WCF Ria?

≡放荡痞女 提交于 2019-12-11 20:39:03

问题


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.

For this i am using WCF Ria Services.

Steps i have followed are :

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

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 :

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}.

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

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

Please Suggest.


回答1:


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.

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

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
}

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();

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
};



回答2:


If you already have the Insert method on your Domain Service, you should be able to call from the client:

//add your new data to the context
MyDomainServiceContext.Entity.Add(myEntity); //(where "Entity" is your entity Type)
//send all the changes to the server
MyDomainServiceContext.SubmitChanges();


来源:https://stackoverflow.com/questions/9293100/unable-to-use-methods-from-domain-service-class-in-wcf-ria

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!