2012-11-20 5 views
0

웹 서비스와 통신하고 응답 값을 얻기위한 프로그램을 작성했습니다. 내가 라인에서 requestDump = NULL로 끝나는 프로그램을 디버깅 할 때 androidHttpTransport.call(SOAP_ACTION, envelope); 그냥이 새로운 하나를 서비스 AsyncTask를 대체 어떤 사람이 나에게 오류의 원인을 말할 수와 나는이Android Soap 웹 서비스 프록시 서버의 오류

public class WebService extends Activity { 
     private final String NAMESPACE = "http://tempuri.org/"; 
     private final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx"; 
     private final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit"; 
     private final String METHOD_NAME = "CelsiusToFahrenheit"; 
    String celsius; 
    Button b; 
    TextView tv; 
    EditText et; 
    String res,resultval; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_web_service); 
     et=(EditText)findViewById(R.id.editText1); 

     tv=(TextView)findViewById(R.id.Result); 
     b=(Button)findViewById(R.id.button1); 
     b.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
      //String result=getFarenheit(et.getText().toString()); 
      //tv.setText(result+"°F"); 
      new service().execute(); 
      } 
     }); 
    } 
    private class service extends AsyncTask<Void, Void, String>{ 

     @Override 
     protected String doInBackground(Void... arg0) { 
      celsius=et.getText().toString(); 
      SoapObject request= new SoapObject(NAMESPACE, METHOD_NAME); 
      PropertyInfo celsuiusPI= new PropertyInfo(); 
      celsuiusPI.setName("Celsius"); 
      celsuiusPI.setValue(celsius); 
      celsuiusPI.setType(String.class); 
      request.addProperty("XMLMarks",celsuiusPI); 
      SoapSerializationEnvelope envelope=new SoapSerializationEnvelope (SoapEnvelope.VER11); 
      envelope.dotNet=true; 
      envelope.implicitTypes = true; 
      envelope.enc = SoapSerializationEnvelope.ENC2003; 
      envelope.xsd = SoapEnvelope.XSD; 
      envelope.xsi = SoapEnvelope.XSI; 
      envelope.setOutputSoapObject(request); 
      envelope.setAddAdornments(false); 
      SoapPrimitive response; 

      HttpTransportSE androidHttpTransport=new HttpTransportSE(URL); 
      try{ 
       androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
       androidHttpTransport.debug = true; 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       String dump= androidHttpTransport.requestDump.toString(); 
       response=(SoapPrimitive)envelope.getResponse(); 
       Toast.makeText(WebService.this, response.toString(), 20).show(); 
       Log.i("WebService output", response.toString()); 
       System.out.println("WebService Response"+response.toString()); 
       Object res= response.toString(); 
       resultval=(String) res; 
      } 
      catch(Exception e){ 
       e.printStackTrace(); 
      } 

      return res; 

     } 
     protected void onPostExecute(String h){ 
      String result=h; 

       tv.setText(result+"°F"); 

    } 


} 
} 
+0

당신이 androidHttpTransport.setXmlVersionTag으로 무엇을 (""); 그것을 할 필요가 없습니다. SOAP은 단지 당신에게 응답합니다. 당신은 xml 구조에서 파싱 할 필요가 없다. –

답변

1

을 위해 무엇을 할 수 있으며,

코드 : 결과를 참조

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

    @Override 
    protected String doInBackground(Void... arg0) { 
     System.out.println("In DoIn Background"); 

     // Initialize soap request + add parameters 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     // Use this to add parameters 
     request.addProperty("Celsius", txtCel.getText().toString()); 

     // Declare the version of the SOAP request 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
       SoapEnvelope.VER11); 

     envelope.setOutputSoapObject(request); 
     envelope.dotNet = true; 

     try { 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

      // this is the actual part that will call the webservice 
      androidHttpTransport.call(SOAP_ACTION, envelope); 

      // Get the SoapResult from the envelope body. 
      SoapObject result = (SoapObject) envelope.bodyIn; 

      if (result != null) { 
       // Get the first property and change the label text 
       // txtFar.setText(result.getProperty(0).toString()); 
       res = result.getProperty(0).toString(); 
      } else { 
       Toast.makeText(getApplicationContext(), "No Response", 
         Toast.LENGTH_LONG).show(); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

     return res; 

    } 

    protected void onPostExecute(String h) { 
     String result = h; 

     tv.setText(result + "°F"); 

    } 

} 
+0

아직도 내가 null'F 결과로 그 물건은 iam입니다. requestDump는 null입니다. HTTPTransportSE에 프록시를 추가하는 방법 –

+0

위의 코드를 복사하여 프로젝트를 실행 했습니까? 아니면 앱에서 더 많은 작업을 했습니까 ?? 내가 여기서 성공적으로 실행할 수 있기 때문에. –

+0

답변을 얻길 바랍니다. 당신은 또한 upvote 수 있습니다. 그래서 다른 사람들을 도울 수 있습니다. –