0

この 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();
}
}

そして、私は得ました:

org.xmlpull.v1.XmlPullParserException: 終了していないエンティティ ref (位置:TEXT ?

私の問題はクラス「コンスタンテ」にあると思いますが、使用する正しい形式がわかりません。

アドバイスやコードの解決策は私にとって良いでしょう。

あなたの助けと時間を前もってありがとう

4

1 に答える 1

0

チャートリリックを使用してテストしたところ、歌詞が得られました。コードを共有します。

public class Constante {
    public static final String SOAP_ACTION = "http://api.chartlyrics.com/SearchLyricDirect";
    public static final String METHOD_NAME = "SearchLyricDirect";
    public static final String NAMESPACE = "http://api.chartlyrics.com/";
    public static final String URL = "http://api.chartlyrics.com/apiv1.asmx";
    public static final String KEY_ARTIST = "artist";
    public static final String KEY_SONG = "song";
}

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
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 run2() throws SoapFault {
        SoapObject request = new SoapObject(Constante.NAMESPACE,
                Constante.METHOD_NAME);
        request.addProperty(Constante.KEY_ARTIST, "U2");
        request.addProperty(Constante.KEY_SONG, "One");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(
                Constante.URL);
        try {
            // call the web service method
            androidHttpTransport.call(Constante.SOAP_ACTION, envelope);
        } catch (Exception e) {
            e.printStackTrace();
        }// Next task is to get Response and format that response
        SoapObject obj;
        obj = (SoapObject) envelope.getResponse();

//      System.out.println(obj);

        System.out.println(obj.getProperty("TrackId"));
        System.out.println(obj.getProperty("LyricChecksum"));
        System.out.println(obj.getProperty("LyricId"));
        System.out.println(obj.getProperty("LyricSong"));
        System.out.println(obj.getProperty("LyricArtist"));
        System.out.println(obj.getProperty("LyricUrl"));
        System.out.println(obj.getProperty("LyricCovertArtUrl"));
        System.out.println(obj.getProperty("LyricRank"));
        System.out.println(obj.getProperty("LyricCorrectUrl"));
        System.out.println(obj.getProperty("Lyric"));

    }

    public static void main(String[] args) {
        try {
            run2();
        } catch (SoapFault e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

LyricWiki の石鹸 API を使用したいと考えています。

よろしく。

于 2013-08-15T09:28:51.853 に答える