سؤال

Aplication hangs just when service is restarted , do not when server is running or is stopped,

There is a discussion on google groups about this problem, I dont know if its related to the Android Emulator or not. 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); 

            }

    }
    }
هل كانت مفيدة؟

المحلول

Have you tried setting a timeout? client.Timeout = 1000; which would be 1 second.

I tried all of the default code and everything worked fine.

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

Also are you passing in a request at all? Hard to debug your code without the full logic.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top