请确保您已为您的项目启用 RIA 服务。
如果您的服务名称以service
标签结尾,那么您将能够将其转换为上下文,例如我的服务名称,DomainService1
然后在客户端它可以通过DomainContext1
. 如果在服务器端,我的 Domainservice 名称是ABC
,那么我可以直接通过名称访问它,不需要上下文。
服务代码:
[EnableClientAccess]
public class TestService : DomainService
{
public string Hello()
{
return "Hello world!";
}
}
客户端代码:在客户端,您必须声明一个命名空间,例如system.your web project.web.servicesmodel.client
现在,
TestContext test=new TestContext();
test.Hello(getData,null,false);`
// 第一个参数是回调方法,第二个对你来说不重要,第三个是如果发生异常,
public void getData(InvokeOpration<string> value)
{
MessageBox.Show(""+value.Value);
}
现在您可以将 Hello World 作为MessageBox
.