2013-05-13 53 views
-2

这是我的SOAP webservice.i有donn。 Bt它得到了错误。这是我的code.Can任何人都可以帮助我在android中解析字符串。 INT 串 INT INT 串 串 在此先感谢。如何解析<strxml>字符串</strxml>使用肥皂?

public boolean callwebservice() { 

    boolean result = false; 
    int patid = 1; 
    String xml = ""; 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    request.addProperty("PatientId", patid); 

    request.addProperty("AppointMentDate", appdate); 
    request.addProperty("TimeFrom", apptimeto); 
    request.addProperty("TimeTo", appfrom); 
    request.addProperty("ReasonForAppointMent", appreason); 
    request.addProperty("strxml", xml); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
      SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 
    HttpTransportSE httpTransport = new HttpTransportSE(URL); 
    httpTransport.debug = true; 
    try { 

     httpTransport.call(SOAP_ACTION, envelope); 
     httpTransport 
       .setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
     // SoapObject response = (SoapObject) envelope.bodyIn; 
     SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); 

     System.out.println("myApp" + response.toString()); 
     System.out.println("response" + response); 

     if (response.toString().equalsIgnoreCase("false")) { 
      result = true; 

     } 

    } catch (SocketException ex) { 
     System.out.println("Error : " + "Error on soapPrimitiveData() " 
       + ex.getMessage()); 
     ex.printStackTrace(); 
    } catch (Exception e) { 
     System.out.println("Error : " + "Error on soapPrimitiveData() " 
       + e.getMessage()); 
     e.printStackTrace(); 
    } 
    return result; 
+0

我已经做使用soap.bt即开始时登录后重定向到任命我得到error.my阙是如何得到的XML响应。 – 2013-05-13 11:25:32

回答

0

首先将ksoap2库导入到您的项目中,然后尝试此操作。 Here is the link

public class MainActivity extends Activity { 
private final String NAMESPACE = "http://www.webserviceX.NET/"; 
private final String URL = "http://www.webservicex.net/CurrencyConvertor.asmx"; 
private final String SOAP_ACTION = "http://www.webserviceX.NET/ConversionRate"; 
private final String METHOD_NAME = "ConversionRate"; 
SoapObject request; 
String weight; 
String fromUnit; 
String toUnit; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    request = new SoapObject(NAMESPACE, METHOD_NAME); 

    weight = "USD"; 
    fromUnit = "INR"; 
    toUnit = "Kilograms"; 

    PropertyInfo weightProp =new PropertyInfo(); 
    weightProp.setName("FromCurrency"); 
    weightProp.setValue(weight); 
    weightProp.setType(String.class); 
    request.addProperty(weightProp); 

    PropertyInfo fromProp =new PropertyInfo(); 
    fromProp.setName("ToCurrency"); 
    fromProp.setValue(fromUnit); 
    fromProp.setType(String.class); 
    request.addProperty(fromProp); 



    //calling the AsyncTask 
    new Task().execute(); 


} 
class Task extends AsyncTask<Void, Void, Void>{ 
    SoapPrimitive response; 
    @Override 
    protected Void doInBackground(Void... params) { 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet = true; 
     envelope.setOutputSoapObject(request); 
     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

     try { 
      androidHttpTransport.call(SOAP_ACTION, envelope); 
      response = (SoapPrimitive)envelope.getResponse(); 
      Log.i("myApp", ""+response); 



     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     // TODO Auto-generated method stub 
     return null; 
    } 
    @Override 
    protected void onPostExecute(Void result) { 
     // TODO Auto-generated method stub 
     TextView tv = new TextView(getApplicationContext()); 
     tv.setText("1"+weight+" equals "+response.toString()+ " "+fromUnit); 
     tv.setTextSize(50); 
     setContentView(tv); 
     super.onPostExecute(result); 
    } 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

}