晚上好,我很长时间尝试使用一个简单的WS,已经研究并尝试了不同的方法来解决这个错误并且失败了,尝试了不同版本的kSOAP,2.5.2,2.6.0,3.0.0 ,3.3,0。 ..Gostaria喜欢知道如何解决。每次我来" transporte.call(SOAP_ACTION sobre);"生成一个空异常。 PS:WS是免费的,这是他们想要访问的链接: http://www.w3schools.com/webservices/tempconvert.asmx
这是我的代码:
private static final String SOAP_ACTION = "http://tempuri.org/CelsiusT oFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit";
private static final String NAMESPACE = "http://tempuri.org";
private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView)findViewById(R.id.textView1);
try{
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
request.addProperty("Celsius", "32");
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sobre.dotNet = true;
sobre.setOutputSoapObject(request);
HttpTransportSE transporte = new HttpTransportSE(URL, 30000);
transporte.call(SOAP_ACTION, sobre);
SoapPrimitive resultado = (SoapPrimitive)sobre.getResponse();
tv.setText("" + resultado.toString());
}catch(Exception e){
tv.setText(e.getMessage());
}
}
感谢您分享知识!
答案 0 :(得分:0)
您的命名空间,方法和肥皂操作错误
private static final String SOAP_ACTION = "http://www.w3schools.com/webservices/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit";
private static final String NAMESPACE = "http://www.w3schools.com/webservices/";
希望有所帮助
修改强>
这有效:
private static final String SOAP_ACTION = "http://www.w3schools.com/webservices/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit";
//private static final String NAMESPACE = "http://www.w3schools.com/webservices";
private static final String NAMESPACE = "http://www.w3schools.com/webservices/";
//private static final String NAMESPACE = "http://www.w3schools.com/webservices/";
private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
//private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
String result = "";
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView)findViewById(R.id.textView1);
try{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Celsius", "32");
final SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sobre.dotNet = true;
sobre.setOutputSoapObject(request);
final HttpTransportSE transporte = new HttpTransportSE(URL, 30000);
new Thread(new Runnable() {
@Override
public void run() {
try {
transporte.call(SOAP_ACTION, sobre);
SoapPrimitive resultado = (SoapPrimitive)sobre.getResponse();
result = resultado.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
int countWait = 5;
while (result.isEmpty() && countWait > 0){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
countWait--;
}
tv.setText(result);
}catch(Exception e){
tv.setText(e.getMessage());
}
}
问题在于您无法在主线程中执行网络操作。加上一些命名空间和其他常量问题。
答案 1 :(得分:0)
来自哔叽工作的代码,但需要一些东西
不要看到线程所以,需要警察在主踏板上进行访问添加此
`StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()。permitAll()。build();
StrictMode.setThreadPolicy(策略);
或使用asinctask
neo4j-import
}