RestSharp ExecuteAsync在Monodroid上挂起

时间:2014-04-20 00:20:51

标签: android c#-4.0 mono xamarin.android restsharp

应用程序在重新启动服务时挂起, 当服务器正在运行或停止时,请不要

谷歌小组讨论了这个问题,    我不知道它是否与Android模拟器有关。    https://groups.google.com/forum/#!topic/restsharp/SMl7sBN72xE

class WService {

    static string BaseUrl = "http://Server:8732/Service1/";

    public static void ExecuteAndGetRestResponse(string controller, JObject data, Action<Object> callbackRespuesta)
    {

        try {

            var json = JsonConvert.SerializeObject(data);

            var request = new RestRequest(controller, Method.POST);
            request.AddParameter("text/json", json, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;
            request.Timeout=10000;

            ExecuteAndGetRestResponse(request,  callbackRespuesta);
        }
        catch{

            Log.Info ("Testing", "ExecuteAndGetRestResponse No descripcion");
        }
    }

    static void ExecuteAndGetRestResponse(RestRequest request, Action<Object> callbackRespuesta)
    {

        var client = new RestClient();
        client.BaseUrl = BaseUrl;

            try {
                client.ExecuteAsync (request, response => {
                    Log.Info ("Testing", "si se lanza");

                    try {
                        callbackRespuesta (response);

                    } catch (Exception e) {
                        callbackRespuesta (e);
                    } 


                });

            } catch (Exception e) {
                Log.Info ("Testing", e.Message);
                callbackRespuesta (e); 

            }

    }
    }

1 个答案:

答案 0 :(得分:0)

您是否尝试过设置超时? client.Timeout = 1000;这将是1秒。

我尝试了所有默认代码,一切正常。

var client = new RestClient ("http://hellodadfadf");
client.Timeout  = 1000;
var request = new RestRequest (String.Format ("{0}/allinfo", "198440"));
client.ExecuteAsync (request, response => {
  Console.WriteLine (response.Content);
});

你还要传递一个请求吗?没有完整的逻辑,很难调试你的代码。