使用包含异步方法调用的Servicestack服务的jquery ajax,从异步方法返回

时间:2013-10-30 09:08:40

标签: c# javascript jquery asynchronous servicestack

我有jquery ajax调用servicestack服务。 servicestack服务调用服务器端的异步方法。 这是场景;

我的服务保存数据并返回没问题的返回对象。

但我需要从异步方法获取响应到jquery客户端

怎么做?请帮忙......

public class MyService : Service
{
    public GenericResponse Any(EditRequest request)
    {
        GenericResponse result = new GenericResponse();

        _repo.Do(request.data, "add");

        result.hasMessage = true;
        result.message.messageType = Enums.MessageTypes.Success;
        result.message.messageData = "save success";

        return result;
    }
}


//_repo methods
public void Do(object data, string oper)
{
    WEBBeanClient client = new WEBBeanClient();
    client.BeginInsert(data, username, password, callback, client);
}

private void callback(IAsyncResult asyncResult)
{
    var client = asyncResult.AsyncState as WEBBeanClient;
    var result= client.EndInsert(asyncResult);
    // need to get return here to jquery client
}

0 个答案:

没有答案