从android执行webservice功能

时间:2015-07-20 09:07:20

标签: web-services devextreme

我有一个网络服务。这是界面:

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

这是svc文件中的实现:

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

现在,我想在devextreme应用程序中调用此SendEmail函数。我正在尝试这个,这显然不起作用(因此这个问题):

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

有人可以帮我从devextreme应用程序执行SendEmail功能吗?

1 个答案:

答案 0 :(得分:0)

请按照下面的步骤操作。

首先,界面应如下所示:

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

第二,在方法实现之上添加WebGet属性:

<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

第三,允许方法通过config方法体内的InitializeService对象进行远程访问:

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

这一切都与服务器端有关。现在可以从JavaScript客户端调用SendEmail方法。我看到你正在使用datajs库,但我建议你使用名为DevExtreme的内置ODataContext类:

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

有关详细信息,请参阅文档link