2013-10-30 2 views
0

웹 서비스 메소드에 액세스하도록 설계된 클래스가 있습니다. 문제는 비동기 호출에서 웹 서비스 메서드의 출력에 액세스하려고 할 때 발생합니다. 비어 있습니다. 나는 어떻게해야합니까?
이 내 웹 서비스 클래스 :웹 서비스의 출력을 가져올 수 없습니다.

package ClassLibrary; 

public class WebService { 
    private String namespace=""; 
    private String url=""; 

    public WebService(String namespace,String url) { 
     super(); 
     this.namespace = namespace; 
     this.url = url; 
    } 

    public String CallMethod(String methodName,PropertyInfo pi) { 
     String result = "default"; 
     SoapObject request = new SoapObject(namespace, methodName); 
     request.addProperty(pi); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet = true; 
     envelope.setOutputSoapObject(request); 
     HttpTransportSE androidHttpTransport = new HttpTransportSE(url); 
     try { 
      androidHttpTransport.call(namespace+methodName, envelope); 
      SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); 
      result= response.toString(); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return result; 
    } 
} 

이 내가 웹 서비스를 호출하기 위해 노력하고있어 어떻게 : 다음과 같다 비동기 작업에서 사용

private class AsyncCallWS extends AsyncTask<String, Void, Void> { 

    private ProgressDialog dialog; 
    private Activity activity; 
    public String wsOutput=""; 
    public String methodName=""; 
    private WebService ws; 

    public AsyncCallWS(Activity activity,String methodName) { 
     this.activity = activity; 
     this.dialog = new ProgressDialog(activity); 
     this.methodName = methodName; 
    } 

    @Override 
    protected Void doInBackground(String... params) { 
     ws = new WebService(PublicVariable.NAMESPACE, PublicVariable.URL); 
     PropertyInfo pi= new PropertyInfo(); 
     pi.setName("UserID"); 
     pi.setValue("1"); 
     pi.setType(String.class); 
     wsOutput=ws.CallMethod("GetPersonalInfo", pi); 

     return null; 
    } 

    @Override 
    protected void onPostExecute(Void result) { 
     if (this.dialog.isShowing()) { 
      this.dialog.dismiss(); 
     } 

     if (methodName == "GetPersonalInfo") { 
      Log.d("Ehsan","OUTPUT IS:"+ wsOutput); 
     } 
    } 
} 

답변

1

세 가지 유형 :

  • 매개 변수는 실행시 작업에 전송되는 매개 변수의 유형입니다.

  • 진행률, 백그라운드 계산 중에 게시 된 진행률 단위의 유형입니다.

  • 결과, 백그라운드 계산 결과의 유형. 백그라운드 계산이 완료된 후

onPostExecute (결과)는 UI 스레드에서 호출된다. 백그라운드 계산의 결과는이 단계에 매개 변수로 전달되며 사용자는 결과 값을 전달하지 않습니다.

private class AsyncCallWS extends AsyncTask<String, Void, String> { 

    private ProgressDialog dialog; 
    private Activity activity; 
    public String methodName=""; 
    private WebService ws; 

    public AsyncCallWS(Activity activity,String methodName) { 
     this.activity = activity; 
     this.dialog = new ProgressDialog(activity); 
     this.methodName = methodName; 
    } 

    @Override 
    protected Void doInBackground(String... params) { 
     ws = new WebService(PublicVariable.NAMESPACE, PublicVariable.URL); 
     PropertyInfo pi= new PropertyInfo(); 
     pi.setName("UserID"); 
     pi.setValue("1"); 
     pi.setType(String.class); 

     String wsOutput = ws.CallMethod("GetPersonalInfo", pi); 

     return wsOutput; 
    } 

    @Override 
    protected void onPostExecute(String result) { 

     if (this.dialog.isShowing()) { 
      this.dialog.dismiss(); 
     } 

     Log.d("Ehsan","OUTPUT IS:"+ result); 
    } 
} 
관련 문제