我正在嘗試爲android創建一個web服務客戶端,但我被卡住了真的很糟糕附加的是我的代碼和WSDL文件。請幫助Android上的SOAP web客戶端
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.me.androidapplication1;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.xmlpull.v1.XmlPullParserException;
/**
*
* @author bansal
*/
public class MainActivity extends Activity {
private String SOAP_ACTION = "http://src/getNews";
private String METHOD_NAME = "getNews";
private String NAMESPACE = "http://src/";
private static final String URL ="http://128.205.201.202:8080/RssService
/RssServiceService?WSDL";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
TextView tv = new TextView(this);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ticker","NASDAQ:INFY");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive p = (SoapPrimitive) envelope.getResponse();
tv.setText("Response " + p);
} catch (Exception ex) {
ex.printStackTrace();
}
setContentView(tv);
// ToDo add your GUI initialization code here
}
}
感謝
我不確定名稱空間,URL和SOAP_ACTION的值是否正確。你可以看看我的WSDL,並告訴他們是否是正確的 - <定義的targetNamespace = 「HTTP:// SRC /」 NAME = 「RssServiceService」> - - - <消息名稱= 「getNews」> <部件名稱= 「parameters」element =「tns:getNews」/> - –
2010-04-09 02:09:22