2014-09-13 5 views
1

Android Azure 모바일 서비스 SDK를 사용하여 Azure 모바일 서비스에 연결하고 있습니다. MobileServiceClient의 invokeApi를 사용할 때 Api가 60 초 내에 완료되면 모든 것이 정상입니다.MobileServiceClient invokeApi timeout

그러나이 API의 내 메소드가 1 분보다 길어질 때 "onCompleted"메소드의 "예외"는 "요청 처리 중 오류"를 표시합니다.

그리고 Android Azure Mobile Services SDK 및 MobileServiceClient 클래스에 대한 모든 문서를 검색 할 때 설정하는 데 약 60 초의 시간 제한 설정과 관련된 설정을 찾을 수 없습니다.

아무도 그것에 대해 밝힐 수 있습니까?

감사합니다.

+0

클라이언트 SDK 또는 서버 실행시 제한 시간이 있습니까? 나는 그것이 클라이언트에서 떠오르고 있다고 확신하지만, 그것이 원래 어디에서 발생 했는가? 사용자 정의 API가 아웃 바운드 HTTP 요청을 작성하는 시간 초과를 초래하는 것은 무엇입니까? –

답변

1
By default azure is using AndroidHttpClient. This has a default socket operation timeout 1 min(SOCKET_OPERATION_TIMEOUT = 60 * 1000) 

우리는 단순히 문제를 해결할 수

HttpConnectionParams.setConnectionTimeout(client.getParams(), SOCKET_OPERATION_TIMEOUT); 
     HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_OPERATION_TIMEOUT); 

    Inside azure sdk there is an interface ServiceFilterRequest and it holds a method 
    public ServiceFilterResponse execute() throws Exception; 

    We can edit this method and add our custom interval as follows. 
    1. Open its implementation class ServiceFilterRequestImpl. 
    2. set a connection interval time 

     // I'm changing the default 1 min to 5 minutes.. 
     private static final int SOCKET_OPERATION_TIMEOUT = 5 * 60 * 1000; 

    3. edit public ServiceFilterResponse execute() throws Exception { } method 

     public ServiceFilterResponse execute() throws Exception { 
      // Execute request 
      AndroidHttpClient client = mAndroidHttpClientFactory.createAndroidHttpClient(); 
      client.getParams().setParameter(HTTP.USER_AGENT, MobileServiceConnection.getUserAgent()); 


//Overriding the default interval with the desired connection timeout value. 
      HttpConnectionParams.setConnectionTimeout(client.getParams(), SOCKET_OPERATION_TIMEOUT); 
      HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_OPERATION_TIMEOUT); 



      try { 
       final HttpResponse response = client.execute(mRequest); 
       ServiceFilterResponse serviceFilterResponse = new ServiceFilterResponseImpl(response); 
       return serviceFilterResponse; 
      } finally { 
       client.close(); 
      } 
     } 

이 같은이를 편집 할 수 있습니다.

+0

이것은 멋지다! 고마워! – Paul

1

오랜 연구 끝에 Android 용 Azure 모바일 서비스가 MobileServiceClient 클래스를 사용하고 AndroidHttpClient를 사용하여 Azure 모바일 서비스 URL과 SSL 통신을한다는 사실이 밝혀졌습니다. 그리고이 게시물 android httpclient hangs on second request to the server (connection timed out)의 AndroidHttpClient에는 SSL 액세스를위한 60 초의 시간 제한 인 기본 "합리적인"설정이 있습니다! OMG.

Android 용 Azure 모바일 서비스 팀에 속한 누군가가이 게시물을 볼 수 있는지, Android 용 Azure 모바일 서비스 클래스에서 직접 시간 제한 설정을 직접 구성 할 수 있는지 알 수 없습니다.

4

사용자 지정 OkHttpClientFactory를 구현하십시오. 예를 들어 :이 클래스의

public class MyOkHttpClientFactory implements OkHttpClientFactory { 
    @Override 
    public OkHttpClient createOkHttpClient() { 
     long timeout = 30_000; 
     TimeUnit unit = TimeUnit.MILLISECONDS; 
     OkHttpClient okClient = new OkHttpClient(); 

     okClient.setConnectTimeout(timeout, unit); 
     okClient.setReadTimeout(timeout, unit); 
     okClient.setWriteTimeout(timeout, unit); 

     return okClient; 
    } 
} 

설정하고 인스턴스 OkHttpClient에 대한

기본 시간 초과 값은 10 초입니다 이것은 나를 위해 작동

MobileServiceClient mobileServiceClient = new MobileServiceClient(SERVICE_URL, Context); 
mobileServiceClient.setAndroidHttpClientFactory(new MyOkHttpClientFactory()); 

MobileServiceClient합니다.