导航:首页 > 操作系统 > 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库相关的资料

热点内容
dvd光盘存储汉子算法 浏览:757
苹果邮件无法连接服务器地址 浏览:962
phpffmpeg转码 浏览:671
长沙好玩的解压项目 浏览:144
专属学情分析报告是什么app 浏览:564
php工程部署 浏览:833
android全屏透明 浏览:736
阿里云服务器已开通怎么办 浏览:803
光遇为什么登录时服务器已满 浏览:302
PDF分析 浏览:484
h3c光纤全工半全工设置命令 浏览:143
公司法pdf下载 浏览:381
linuxmarkdown 浏览:350
华为手机怎么多选文件夹 浏览:683
如何取消命令方块指令 浏览:349
风翼app为什么进不去了 浏览:778
im4java压缩图片 浏览:362
数据查询网站源码 浏览:150
伊克塞尔文档怎么进行加密 浏览:892
app转账是什么 浏览:163