導航:首頁 > 操作系統 > androidwebservice庫

androidwebservice庫

發布時間:2022-11-27 16:07:08

android 調用 Webservice的實現過程

一般後台會開啟一個服務給你或者為了直接方便調試的話,也可以自己用androidStudio 打開這個Webservice項目,如下圖所示:

基本入參都String,因為之前跟後台聯調的時候發現傳對象一直沒成功,就折中改為傳jsonObject的方式,後台再去轉為對象

Ⅱ android怎麼調用webservice

publicclass WebService extends Activity {
privatestaticfinal String NAMESPACE ="http://WebXml.com.cn/";
// WebService地址
privatestatic String URL ="http://www.webxml.com.cn/
webservices/weatherwebservice.asmx";
privatestaticfinal String METHOD_NAME ="getWeatherbyCityName";
privatestatic String SOAP_ACTION ="http://WebXml.com.cn/
getWeatherbyCityName";

private String weatherToday;

private Button okButton;
private SoapObject detail;

@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
okButton = (Button) findViewById(R.id.ok);

okButton.setOnClickListener(new Button.OnClickListener() {
publicvoid onClick(View v) {
showWeather();
}
});
}

privatevoid showWeather() {
String city ="武漢";
getWeather(city);
}

@SuppressWarnings("deprecation")
publicvoid getWeather(String cityName) {
try {
System.out.println("rpc------");
SoapObject rpc =new SoapObject(NAMESPACE, METHOD_NAME);
System.out.println("rpc"+ rpc);
System.out.println("cityName is "+ cityName);
rpc.addProperty("theCityName", cityName);

AndroidHttpTransport ht =new AndroidHttpTransport(URL);
ht.debug =true;

SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(
SoapEnvelope.VER11);

envelope.bodyOut = rpc;
envelope.dotNet =true;
envelope.setOutputSoapObject(rpc);

ht.call(SOAP_ACTION, envelope);

SoapObject result = (SoapObject) envelope.bodyIn;
detail = (SoapObject) result
.getProperty("getWeatherbyCityNameResult");

System.out.println("result"+ result);
System.out.println("detail"+ detail);
Toast.makeText(WebService.this, detail.toString(),
Toast.LENGTH_LONG).show();
parseWeather(detail);

return;
} catch (Exception e) {
e.printStackTrace();
}
}

privatevoid parseWeather(SoapObject detail)
throws UnsupportedEncodingException {
String date = detail.getProperty(6).toString();
weatherToday ="今天:"+ date.split("")[0];
weatherToday = weatherToday +"\n天氣:"+ date.split("")[1];
weatherToday = weatherToday +"\n氣溫:"
+ detail.getProperty(5).toString();
weatherToday = weatherToday +"\n風力:"
+ detail.getProperty(7).toString() +"\n";
System.out.println("weatherToday is "+ weatherToday);
Toast.makeText(WebService.this, weatherToday,
Toast.LENGTH_LONG).show();

}
}

Ⅲ 誰有Android通過WebService連接SQLserver資料庫的例子,那些方法一定要注釋,小弟在次謝謝了!

你首先要搞清楚,android和SQLserver是沒關系的。。。。
是android通過網路訪問webservice,然後是webservice訪問資料庫。
這兩個是分離開的,也就是你需要先把webservice做完,再去做android。
你可以讓webservice返回xml之類的字元串類型的東西,把數據內容返回到頁面,android讀取的就是返回的東西。跟瀏覽器訪問是一個道理的。

實際代碼只有android部分的,大概就是先用url.openConnection()獲取HttpURLConnection對象conn,
new BufferedReader(new InputStreamReader(conn.getInputStream()), 1024 * 1024)這樣能獲取BufferedReader的對象。
非常簡單的就能請求webservice,並且獲取到返回給你的字元串。

素藍手打~ 歡迎復制。

Ⅳ android調用webservice怎麼授權

具體調用調用webservice的方法為:

(1) 指定webservice的命名空間和調用的方法名,如:

SoapObject request =new SoapObject(http://service,」getName」);
SoapObject類的第一個參數表示WebService的命名空間,可以從WSDL文檔中找到WebService的命名空間。第二個參數表示要調用的WebService方法名。

(2) 設置調用方法的參數值,如果沒有參數,可以省略,設置方法的參數值的代碼如下:

Request.addProperty(「param1」,」value」);
Request.addProperty(「param2」,」value」);
要注意的是,addProperty方法的第1個參數雖然表示調用方法的參數名,但該參數值並不一定與服務端的WebService類中的方法參數名一致,只要設置參數的順序一致即可。

(3) 生成調用Webservice方法的SOAP請求信息。該信息由SoapSerializationEnvelope對象描述,代碼為:

SoapSerializationEnvelope envelope=new
SoapSerializationEnvelope(SoapEnvelope.VER11);
Envelope.bodyOut = request;
創建SoapSerializationEnvelope對象時需要通過SoapSerializationEnvelope類的構造方法設置SOAP協議的版本號。該版本號需要根據服務端WebService的版本號設置。在創建SoapSerializationEnvelope對象後,不要忘了設置SOAPSoapSerializationEnvelope類的bodyOut屬性,該屬性的值就是在第一步創建的SoapObject對象。

(4) 創建HttpTransportsSE對象。通過HttpTransportsSE類的構造方法可以指定WebService的WSDL文檔的URL:

HttpTransportSE ht=new HttpTransportSE(「http://192.168.18.17:80
/axis2/service/SearchNewsService?wsdl」);
(5)使用call方法調用WebService方法,代碼:

ht.call(null,envelope);
Call方法的第一個參數一般為null,第2個參數就是在第3步創建的SoapSerializationEnvelope對象。

(6)使用getResponse方法獲得WebService方法的返回結果,代碼:

SoapObject soapObject =( SoapObject) envelope.getResponse();

Ⅳ android怎麼訪問webservice介面

需要引入ksoap2-android-assembly-2.5.2-jar-with-dependencies.jar
//WebService的命名空間
staticfinal
String
namespace
="impl.service.suncreate.com";前面加上http
//伺服器發布的url
staticfinal
String
url
=
10.100.3.41/axis2/services/UploadService;前面加上http
final
String
methodName
="upload";
//
函數名
finalint
sessionID
="111111";
//sessionID
//創建HttpTransportSE對象,通過HttpTransportSE類的構造方法可以指定WebService的url
HttpTransportSE
transport
=new
HttpTransportSE(url);
transport.debug
=true;
//指定WebService的命名空間和函數名
SoapObject
soapObject
=new
SoapObject(namespace,
methodName);
//設置調用方法參數的值
soapObject.addProperty("sessionID",
sessionID);
//sessionID
soapObject.addProperty("data",
cds);
//cds是需要傳遞的對象
SoapSerializationEnvelope
envelope
=new
SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.bodyOut
=
transport;
envelope.setOutputSoapObject(soapObject);
//使用call方法調用WebService方法
transport.call(null,
envelope);
SoapObject
sb
=
(SoapObject)
envelope.bodyIn;
String
xmlMessage
=
sb.toString();
//
獲取從伺服器端返回的XML字元串

Ⅵ android怎麼調用webservice

使用Ksoup.jar包可以實現webservice的調用
參考代碼:
String result = null;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.bodyOut = soapObject;
String endPoint = 地址後綴//如WebService/AppService.asmx
HttpTransportSE transportSE = new HttpTransportSE(endPoint);
SoapObject object = null;
transportSE.call(地址 + soapObject.getName(),
envelope);
object = (SoapObject) envelope.bodyIn;
result = object.getProperty(0).toString();

Ⅶ android怎麼調用webservice

WebService是一種基於SOAP協議的遠程調用標准,通過webservice可以將不同操作系統平台、不同語言、不同技術整合到一塊。在Android SDK中並沒有提供調用WebService的庫,因此,需要使用第三方的SDK來調用WebService。PC版本的WEbservice客戶端庫非常豐富,例如Axis2,CXF等,但這些開發包對於Android系統過於龐大,也未必很容易移植到Android系統中。因此,這些開發包並不是在我們的考慮范圍內。適合手機的WebService客戶端的SDK有一些,比較常用的有Ksoap2,可以從http://code.google.com/p/ksoap2-android/downloads/list進行下載;將下載的ksoap2-android-assembly-2.4-jar-with-dependencies.jar包復制到Eclipse工程的lib目錄中,當然也可以放在其他的目錄里。同時在Eclipse工程中引用這個jar包。
具體調用調用webservice的方法為:
(1) 指定webservice的命名空間和調用的方法名,如:
SoapObject request =new SoapObject(http://service,」getName」);
SoapObject類的第一個參數表示WebService的命名空間,可以從WSDL文檔中找到WebService的命名空間。第二個參數表示要調用的WebService方法名。
(2) 設置調用方法的參數值,如果沒有參數,可以省略,設置方法的參數值的代碼如下:
Request.addProperty(「param1」,」value」);
Request.addProperty(「param2」,」value」);
要注意的是,addProperty方法的第1個參數雖然表示調用方法的參數名,但該參數值並不一定與服務端的WebService類中的方法參數名一致,只要設置參數的順序一致即可。
(3) 生成調用Webservice方法的SOAP請求信息。該信息由SoapSerializationEnvelope對象描述,代碼為:
SoapSerializationEnvelope envelope=new
SoapSerializationEnvelope(SoapEnvelope.VER11);
Envelope.bodyOut = request;
創建SoapSerializationEnvelope對象時需要通過SoapSerializationEnvelope類的構造方法設置SOAP協議的版本號。該版本號需要根據服務端WebService的版本號設置。在創建SoapSerializationEnvelope對象後,不要忘了設置SOAPSoapSerializationEnvelope類的bodyOut屬性,該屬性的值就是在第一步創建的SoapObject對象。
(4) 創建HttpTransportsSE對象。通過HttpTransportsSE類的構造方法可以指定WebService的WSDL文檔的URL:
HttpTransportSE ht=new HttpTransportSE(「http://192.168.18.17:80
/axis2/service/SearchNewsService?wsdl」);
(5)使用call方法調用WebService方法,代碼:
ht.call(null,envelope);
Call方法的第一個參數一般為null,第2個參數就是在第3步創建的SoapSerializationEnvelope對象。
(6)使用getResponse方法獲得WebService方法的返回結果,代碼:
SoapObject soapObject =( SoapObject) envelope.getResponse();
以下為簡單的實現一個天氣查看功能的例子:

publicclass WebService extends Activity {
privatestaticfinal String NAMESPACE ="http://WebXml.com.cn/";
// WebService地址
privatestatic String URL ="http://www.webxml.com.cn/
webservices/weatherwebservice.asmx";
privatestaticfinal String METHOD_NAME ="getWeatherbyCityName";
privatestatic String SOAP_ACTION ="http://WebXml.com.cn/
getWeatherbyCityName";

private String weatherToday;

private Button okButton;
private SoapObject detail;

@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
okButton = (Button) findViewById(R.id.ok);

okButton.setOnClickListener(new Button.OnClickListener() {
publicvoid onClick(View v) {
showWeather();
}
});
}

privatevoid showWeather() {
String city ="武漢";
getWeather(city);
}

@SuppressWarnings("deprecation")
publicvoid getWeather(String cityName) {
try {
System.out.println("rpc------");
SoapObject rpc =new SoapObject(NAMESPACE, METHOD_NAME);
System.out.println("rpc"+ rpc);
System.out.println("cityName is "+ cityName);
rpc.addProperty("theCityName", cityName);

AndroidHttpTransport ht =new AndroidHttpTransport(URL);
ht.debug =true;

SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(
SoapEnvelope.VER11);

envelope.bodyOut = rpc;
envelope.dotNet =true;
envelope.setOutputSoapObject(rpc);

ht.call(SOAP_ACTION, envelope);

SoapObject result = (SoapObject) envelope.bodyIn;
detail = (SoapObject) result
.getProperty("getWeatherbyCityNameResult");

System.out.println("result"+ result);
System.out.println("detail"+ detail);
Toast.makeText(WebService.this, detail.toString(),
Toast.LENGTH_LONG).show();
parseWeather(detail);

return;
} catch (Exception e) {
e.printStackTrace();
}
}

privatevoid parseWeather(SoapObject detail)
throws UnsupportedEncodingException {
String date = detail.getProperty(6).toString();
weatherToday ="今天:"+ date.split("")[0];
weatherToday = weatherToday +"\n天氣:"+ date.split("")[1];
weatherToday = weatherToday +"\n氣溫:"
+ detail.getProperty(5).toString();
weatherToday = weatherToday +"\n風力:"
+ detail.getProperty(7).toString() +"\n";
System.out.println("weatherToday is "+ weatherToday);
Toast.makeText(WebService.this, weatherToday,
Toast.LENGTH_LONG).show();

}
}

Ⅷ 請問Android如何通過WebService連接MySQL資料庫

真正對資料庫數據進行操作的都還是webservice,
把android工程看成是網頁就可以了,網頁向伺服器發送請求,然後伺服器響應.

具體android鏈接伺服器用什麼語句,只要你理解了原理,光靠猜也猜到了.
不要忘記android-webservice-mysql之間的關系就可以了.思路要清晰.
URL載入要訪問的路徑,然後用HttpURLConnection接收url的openConnection,
然後就是各種流包裝來包裝去,
沒了.

Ⅸ webservice android 資料庫

這是服務端的代碼, 你需要在客戶端引用這個WebService

架構C#WebService程序
http://www.csframework.com/archive/5/arc-5-20110714-1723.htm

Ⅹ android通過webservice連接oracle資料庫 具體是怎麼連接的

java 的 webservice,使用cxf 就不錯了,兼容好。

http://download.csdn.net/detail/zhyl8157121/4836107
這個例子是SQL SERVER,不過對JAVA來講,差別不大,如果不是很特別的數據,換一下驅動就可以。

閱讀全文

與androidwebservice庫相關的資料

熱點內容
編譯器錯誤的位置怎麼找到 瀏覽:434
編譯原理操作系統圖形學 瀏覽:843
安卓怎麼玩華為 瀏覽:249
情人節網站源碼 瀏覽:305
設備管理命令行 瀏覽:726
吃哺乳期的電影 瀏覽:190
把加密zip變成文件夾 瀏覽:213
linuxrecv阻塞 瀏覽:46
java模擬cookie 瀏覽:175
主角變身女收女的變百小說 瀏覽:758
粉筆教育app從哪裡看做過的題 瀏覽:391
app數據包在哪裡找到 瀏覽:923
百煉成仙綠帽改編1-11 瀏覽:109
女主和一對雙胞胎兄弟 瀏覽:437
刀劍神域小說TXT 瀏覽:1000
php獲取文件地址 瀏覽:578
linuxsed替換字元 瀏覽:413
如何填寫國家反詐中心app注冊使用 瀏覽:792
日本影視網站 瀏覽:933
伺服器點亮埠以後有什麼特徵 瀏覽:980