Silverlight - created a new domain service, but how do I access it from a client?

I used the SL business application template and added a new empty, empty domain service in my Services folder in the .Web part of the solution. The class is DomainService1 and inherits from DomainService. It contains one method:

public class DomainService1 : DomainService
{
    public string Hello()
    {
        return "Hello World";
    }
}

How do I access this service method from a client? I cannot create an instance of a domain service on all clients.

+3
source share
2 answers

Client code is generated by RIA services.

To access the services that inherit the DomainService, you create a new client-side context.

Replace the Service part with the name Context.

UserService = UserContext, ArticleService = ArticleContext ..

var testContext = new TestContext();
            testContext.Hello();

[EnableClientAccess]
    public class TestService : DomainService
    {
        public string Hello()
        {
            return "Hello world!";
        }
    }
+4

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

0

Source: https://habr.com/ru/post/1753504/


All Articles