安卓在java环境中使用ksoap2从wsdl文件消费服务
我需要您的帮助才能使用此wsdl文件的服务: http://lyrics.wikia.com/server.php?wsdl
例如,参数为“artist=U2”的服务“getArtist”
我开发了以下java代码:
public class Constante {
public static final String SOAP_ACTION = "LyricWiki#getArtist";
public static final String METHOD_NAME = "getArtist";
public static final String NAMESPACE = "LyricWiki";
public static final String URL = "http://lyrics.wikia.com/server.php";
public static final String KEY_ARTIST = "artist";
}
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
public class TestWSDL {
public static void run() {
SoapObject soapclient = new SoapObject(Constante.NAMESPACE, Constante.METHOD_NAME);
// Yes you need this one in order to send the whole string or else only
// the first letter
// is going to be send
SoapObject parameters = new SoapObject(Constante.NAMESPACE, Constante.METHOD_NAME);
parameters.addProperty(Constante.KEY_ARTIST, "U2");
soapclient.addProperty(Constante.METHOD_NAME, parameters);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(soapclient);
HttpTransportSE httpTransportSE = new HttpTransportSE(Constante.URL);
try {
httpTransportSE.call(Constante.SOAP_ACTION, envelope);
Object result = envelope.getResponse();
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
run();
}
}
我得到了:
组织。拉。v1。XmlPullParserException:未终止的实体引用(位置:文本
我认为我的问题在于“Constante”类,但我不知道使用正确的格式
任何建议或代码解决方案都对我有好处
提前感谢您的帮助和时间
# 1 楼答案
我用ChartLyps测试了一下,得到了歌词, 现在,我与大家分享我的代码:
我希望使用LyricWiki soap api
问候