Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何解析<;strxml>;字符串</strxml>;使用肥皂?_Android_Ksoap2_Android Ksoap2 - Fatal编程技术网

Android 如何解析<;strxml>;字符串</strxml>;使用肥皂?

Android 如何解析<;strxml>;字符串</strxml>;使用肥皂?,android,ksoap2,android-ksoap2,Android,Ksoap2,Android Ksoap2,这是我的SOAP网络服务。我有donn。Bt出现错误。这是我的代码。有人能帮我吗。如何在android中解析字符串。 int 一串 int int 一串 一串 提前谢谢 public boolean callwebservice() { boolean result = false; int patid = 1; String xml = ""; SoapObject request = new SoapObject(NAMESPACE, METHOD_NAM

这是我的SOAP网络服务。我有donn。Bt出现错误。这是我的代码。有人能帮我吗。如何在android中解析字符串。 int 一串 int int 一串 一串 提前谢谢

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;
public boolean callwebservice(){
布尔结果=假;
int-patid=1;
字符串xml=”“;
SoapObject请求=新的SoapObject(名称空间、方法名称);
request.addProperty(“PatientId”,patid);
请求。添加属性(“任命日期”,应用日期);
addProperty(“TimeFrom”,apptimeto);
request.addProperty(“TimeTo”,appfrom);
请求。添加属性(“申请理由”,通知);
addProperty(“strxml”,xml);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(
第11版);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
HttpTransportSE httpTransport=新的HttpTransportSE(URL);
httpTransport.debug=true;
试一试{
调用(SOAP_操作,信封);
高温超导输运
.setXmlVersionTag(“”);
//SoapObject响应=(SoapObject)envelope.bodyIn;
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
System.out.println(“myApp”+response.toString());
System.out.println(“响应”+响应);
if(response.toString().equalsIgnoreCase(“false”)){
结果=真;
}
}捕获(SocketException例外){
System.out.println(“错误:”+“soapPrimitiveData()上的错误”
+例如getMessage());
例如printStackTrace();
}捕获(例外e){
System.out.println(“错误:”+“soapPrimitiveData()上的错误”
+e.getMessage());
e、 printStackTrace();
}
返回结果;

首先将ksoap2库导入到项目中,然后尝试此操作

公共类MainActivity扩展活动{
私有最终字符串命名空间=”http://www.webserviceX.NET/";
私有最终字符串URL=”http://www.webservicex.net/CurrencyConvertor.asmx";
私有最终字符串SOAP_ACTION=”http://www.webserviceX.NET/ConversionRate";
私有最终字符串方法\u NAME=“ConversionRate”;
SoapObject请求;
线重;
字符串单位;
串珠;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
请求=新的SoapObject(名称空间、方法名称);
重量=“美元”;
fromUnit=“INR”;
toUnit=“千克”;
PropertyInfo weightProp=新的PropertyInfo();
weightProp.setName(“FromCurrency”);
weightProp.setValue(重量);
setType(String.class);
request.addProperty(weightProp);
PropertyInfo fromProp=新的PropertyInfo();
fromProp.setName(“ToCurrency”);
fromProp.setValue(fromUnit);
fromProp.setType(String.class);
request.addProperty(fromProp);
//调用异步任务
新任务().execute();
}
类任务扩展了异步任务{
原始反应;
@凌驾
受保护的Void doInBackground(Void…参数){
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
试一试{
调用(SOAP_操作,信封);
response=(SoapPrimitive)envelope.getResponse();
Log.i(“myApp”和“+”响应);
}捕获(例外e){
e、 printStackTrace();
}
//TODO自动生成的方法存根
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
//TODO自动生成的方法存根
TextView tv=新的TextView(getApplicationContext());
tv.setText(“1”+weight+”等于“+response.toString()+”+fromUnit);
电视.setTextSize(50);
设置内容视图(电视);
super.onPostExecute(结果);
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}

}

我已经使用soap.bt进行了登录,在重定向到约会后,我遇到了错误。我的问题是如何以xml获取响应。
 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;
}