我正在使用实时数据制作货币转换器,使用 ksoap 访问网络服务。然而,来自 web 服务的响应是 org.ksoap2.SoapFault。但是这个答案并没有作为异常抛出。这个答案出现在我的文本区域我的代码有什么问题?
这是源代码:
package com.example.deneme;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView input;
TextView output;
Button convert;
private static final String NAMESPACE = "http://www.webserviceX.NET/";
private static String URL = "http://www.webserviceX.NET/CurrencyConvertor.asmx";
private static final String METHOD_NAME = "ConversionRate";
private static final String SOAP_ACTION = "http://www.webserviceX.NET/ConversionRate";
// Yararlanacağımız web servisin yerini belirtiyoruz.
/*
final static String NAMESPACE = "http://tempuri.org/";
// Web servis üzerinde hangi metodu kullanacağımızı ayarlıyoruz.
final static String METHOD_NAME = "CelsiusToFahrenheit";
// SOAP_ACTION : NAMESPACE ve METHOD_NAME birleşiminden oluşuyor.
final static String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
// Son olarak Web servise ait URL tanımlamasını burada yapıyoruz.
final static String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input=(EditText)findViewById(R.id.editText1);
convert=(Button)findViewById(R.id.convertt);
convert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
/*
PropertyInfo propInfo=new PropertyInfo();
propInfo.name="FromCurrency";
propInfo.type=PropertyInfo.STRING_CLASS;
propInfo.setValue("GBP");
PropertyInfo propInfo2 = new PropertyInfo();
propInfo2.name="ToCurrency";
propInfo2.type = PropertyInfo.STRING_CLASS;
propInfo2.setValue("EUR");
*/
// request.addProperty(propInfo);
//request.addProperty(propInfo2);
request.addProperty("FromCurrency","GBP");
request.addProperty("ToCurrency","AFA");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet=true;
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
try {
httpTransport.call(SOAP_ACTION, envelope);
System.out.println("2!!!!!!!!!!!!!!!!");
SoapObject result = (SoapObject)envelope.bodyIn;
System.out.println("1!!!!!!!!!!!!!!!!");
input.setText(result.getProperty(0).toString());
} catch (Exception e) {
input.setText(e.getMessage());
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}][1]
[1]: http://i.stack.imgur.com/QtUoD.png