`
whistler
  • 浏览: 24778 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

MyEclipse5.5三分钟实现java访问公网.net webservice

阅读更多

在网上搜索到一个基金网站开放的.net webservice 接口:(网址:http://www.fundxy.com/public/fundvalueapi.htm)
下面是其中一个接口:
1.获取最新基金净值列表
接口:GetNewFundValue(int FundType, int SortType, int AscFlag)
参数说明:
FundType:基金类型
0:全部基金
1:开放式基金
2:货币基金
3:ETF/LOF基金
4:封闭式基金
SortType:列表排序类型
0:基金名称
1:单位净值
2:累计净值
3:日增长率
4:日增长值
AscFlag:升序/降序
0:升序
1:降序
返回结果:
由以下格式组成的N个数据:
基金名称
基金代码
日期(格式:2006-09-19)
单位净值
累计净值
日增长率
XML Web service 开放接口
XML Web service 接口地址:
http://www1.fundxy.com/fundxy/Common/FundxyPublic.asmx


 下面开始创建webservice客户端,访问上面的接口
1.新建web project :test;
2.右键单击工程名称,选择MyEclipse,左键单击 Add Web Service capabilities…; 弹出如下窗口,单击Configuration Folder 的浏览按钮,选择webroot/web-inf 目录,单击下一步选择类库,我只选择了xfire 1.2 Core Libraries ,单击finish按钮成。           

  3.右键单击工程名称,选择new ,左键单击 other…;  在弹出窗口选择MyEclipe web services webservice  client; 

 4.单击next 按钮,在new web service client 窗口中Project选择test

   选择 WSDL URL 填入 http://www1.fundxy.com/fundxy/Common/FundxyPublic.asmx?wsdl

   在java package 一栏单击new 按钮,新建 com.test.webservice 包;

一路next,完成后生成如下类:

(为什么会生成如下类,请参考 web  Service描述语言 WSDL 详解

 5. FundxyPublicClient.java中的main方法中加入如下代码

  1. public static void main(String[] args) {   
  2.            
  3.   
  4.         FundxyPublicClient client = new FundxyPublicClient();   
  5.            
  6.         //create a default service endpoint   
  7.         FundxyPublicSoap service = client.getFundxyPublicSoap();   
  8.            
  9.         //TODO: Add custom client code here   
  10.                 //   
  11.                 //service.yourServiceOperationHere();   
  12.         //添加的代码 开始   
  13.         ArrayOfFundValue afv = service.getNewFundValue(000);   
  14.            
  15.         for(Iterator it = afv.getFundValue().iterator();it.hasNext();)   
  16.         {   
  17.             FundValue fv = (FundValue)it.next();   
  18.             System.out.print(fv.getFundID()+"            ");   
  19.             System.out.print(fv.getFundName()+"            ");   
  20.             System.out.println(fv.getTodayValue()+"            ");   
  21.         }   
  22. //      添加的代码 结束   
  23.         System.out.println("test client completed");   
  24.                 System.exit(0);   
  25. }   

  右键单击FundxyPublicClient.java,选择Run as ,单击 Java Application ,作为java应用程序运行FundxyPublicClient.java,控制台输出如下:

240002            宝康灵活配置基金            1.533            <o:p></o:p>

240001            宝康消费品基金            1.2322            <o:p></o:p>

240003            宝康债券型基金            1.193            <o:p></o:p>

213003            宝盈策略增长股票基金            1.3421            <o:p></o:p>

213002            宝盈泛沿海区域增长基金            1.6873            <o:p></o:p>

213001            宝盈鸿利收益基金            1.066            <o:p></o:p>

050008            博时第三产业成长股票基金            1.062            <o:p></o:p>

050201            博时价值增长贰号基金            1.475            <o:p></o:p>

050001            博时价值增长基金            1.366            <o:p></o:p>

050004            博时精选股票基金            1.3771            <o:p></o:p>

050007            博时平衡配置混合基金            1.01            <o:p></o:p>

050006            博时稳定价值债券基金            1.0042            <o:p></o:p>

050003            博时现金收益基金            0.6479            <o:p></o:p>

050002            博时裕富指数基金            1.015            <o:p></o:p>

160505            博时主题行业基金            1.9402            <o:p></o:p>

200007            长城安心回报混合基金            1.5908            <o:p></o:p>

200003            长城货币基金            0.5826            <o:p></o:p>

162006            长城久富核心成长股票基金            1.2508  

.......................

分享到:
评论
1 楼 raulos 2007-09-21  
http://www1.fundxy.com/fundxy/Common/FundxyPublic.asmx?wsdl
现在无法访问,郁闷

相关推荐

Global site tag (gtag.js) - Google Analytics