.net调用java编写的webservice

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下测试通过。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值