webservice服务端基于xfire,至于如何创建基于xfire的服务端,网上有很多文章就不再阐述。
.
JAVA:
pojo:
public class GpsInfo {
private String carNum; //车牌
private double dwlongitude; //经度
private double dwlatitude; //纬度
private int status; //0在线1不在线
}
方法:
public List<GpsInfo> findGPSInfoByIDs(String deviceIDSTRs){
GPSInfoJdbcUtil gpsInfoJdbcUtil= new GPSInfoJdbcUtil();
List<GpsInfo> list = new ArrayList<GpsInfo>();
list = gpsInfoJdbcUtil.queryGpsInfoByIDs(deviceIDSTRs);
return list;
}
方法说明:传入一个车牌号(多个以逗号相连)字符串,返回一个list,里面的对象是GpsInfo类的实例。
.
.
.net(C#)
菜单-->项目-->添加服务引用,填写地址 http://192.168.1.174:8080/gps/services/XXX?wsdl(以实际地址和方法为准),命名空间为:ServiceReference1,确定。
确定后,项目文件夹会多出ServiceReference1目录,里面自动生成了Reference.cs,自动生成了访问webservice的框架代码,我们只需要调用即可。
private void button1_Click(object sender, EventArgs e)
{
ServiceReference1.GpsInfoPortType service = new ServiceReference1.GpsInfoPortTypeClient();
ServiceReference1.GpsInfo[] gpsInfo = service.findGPSInfoByIDs("'沪A87654','苏A08203'");
foreach (ServiceReference1.GpsInfo o in gpsInfo)
{
String s = o.carNum + ","+ o.dwlongitude + "," + o.dwlatitude;
textBox1.Text += s + "/r/n";
}
}
本例在MyEclipse6.5, XFire1.2, VisualStudio2008下测试通过。