我想使用库 ksoap2 在 Android 中发送和接收 SOAP 消息,但我无法让它在 Eclipse 中工作。它不断地给我信息SoapObject cannot be resolved to a type
。我复制Soap
了从这个答案中得到的类的代码(让它首先工作,然后根据我的需要进行编辑)并使用这个问题的导入。我对 Android 开发、Java 和 Eclipse 不是很有经验,所以我可能忽略了一些东西。
package com.example.myapp;
import android.content.Context;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
public class Soap {
Context context;
int viPeriod;
String vsUserID;
String NAMESPACE = "http://localhost/soap/";
String SOAP_ACTION = "http://localhost/soap/bin/SOAP.dll";
String METHOD_NAME = "SOAP";
public String result = null;
Object resultRequestSOAP = null;
public Soap(Context context) {
this.context = context;
}
public void SendSoap() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("viPeriod", viPeriod);
request.addProperty("vsUserID", vsUserID);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
String requestDumpString = androidHttpTransport.requestDump;
System.out.println("requestDump : " + requestDumpString);
resultRequestSOAP = envelope.getResponse(); // Output received
result = resultRequestSOAP.toString(); // Result string
System.out.println("OUTPUT : " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
在 Eclipse 4.2.2 项目的 libs 文件夹中是文件ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar
.
我究竟做错了什么?你能指出我正确的方向吗?或者也许建议我以不同的方式解决这个问题。
在此先感谢,敬业。