0

I have a web service. This is the interface:

<ServiceContract()>
Public Interface IService1
    <OperationContract()> _
    Function SendEmail(EmailAddress As String) As Boolean
End Interface

This is the implementation inside the svc file :

Public Function SendEmail(emailaddress As String) As Boolean Implements IService1.SendEmail
    Return Extras.SendEmail(0, 22, emailaddress, "test Email", "Test Email", 0)
End Function

Now, I would like to call this SendEmail function from within my devextreme application. I am trying this, which obviously does not work ( hence this question ):

                 client = new DefaultHttpClient();

                request = new HttpGet(_URL + "/SendEmail(email@subdomain.com");
                request.setHeader("Accept", "application/json");
                request.setHeader("Content-type", "application/json");

                 httpClient = new DefaultHttpClient();
                 response = httpClient.execute(request);
                 responseEntity = response.getEntity();

Can anyone please help me execute the SendEmail function from my devextreme app?

seteh
  • 389
  • 4
  • 13

1 Answers1

0

Please, follow the steps bellow.

In first, the interface should look like this:

Public Interface IService1
    Inherits IServiceProvider
    Function SendEmail(EmailAddress As String) As Boolean
End Interface

In second, add the WebGet attribute above the method implementation:

<WebGet> _
Public Function SendEmail(emailAddress As String) As Boolean Implements IService1.SendEmail
    Return DateTime.Now.Ticks Mod 2 <> 0 'Replace with actual code
End Function

In third, allow method remote access through config object inside InitializeService method body:

config.SetServiceOperationAccessRule("SendEmail", ServiceOperationRights.AllRead)

That's all with server side. Now the SendEmail method can be called from JavaScript client. As I see, you're using datajs library, but I would recommend you to use built-in DevExtreme class called ODataContext:

new DevExpress.data.ODataContext({ url: "http://your.domain/DataService.svc" })
    .get("SendEmail", { emailAddress: "hello" })
        .done(handleDone)
        .fail(handleFail);

For more information please follow documentation link.

seteh
  • 389
  • 4
  • 13