java wsdl反向生成源码,并使用CXF实现客户端调用代码

本文介绍如何使用Java创建Webservice客户端,包括通过wsdl链接生成源码、导入CXF相关jar包及编写查询代码的具体步骤。通过示例演示了如何实现基于IMSI的用户登录验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


                
1.   查询对方提供的wsdl链接,通过该链接以及wsdl工具生成源码文件。
      eg:  wsdl地址为:http://sersh.passport.189.cn/UDBAPPInterface/UDBAPPSYS/AccountLogin.asmx?WSDL

      打开cmd,输入如下命令:wsimport -extension -s d:/test http://sersh.passport.189.cn/UDBAPPInterface/UDBAPPSYS/AccountLogin.asmx?WSDL


2.   上apache官网,下载CXF相关jar包。(apache-cxf-2.7.4.zip)

3.   导入相关jar包至项目中,编写客户端查询代码。(前提是Webservice服务端已经部署完毕)

      

  1.     public static void main(String[] args) throws MalformedURLException {  
  2.           
  3.         System.out.println("start.");  
  4.         IMSILoginResult login = getIMSILoginResultFromQGUDBByImsi("460030136905408");  
  5.         System.out.println("mobile is " + login.getUserID());  
  6.           
  7.     }  
  8.   
  9.     private static String serviceUrl = "http://sersh.passport.189.cn/UDBAPPInterface/UDBAPPSYS/AccountLogin.asmx?WSDL";  
  10.   
  11.     private static String QGUDB_DEVICENO = "3500000000408501";  
  12.     private static String QGUDB_DESKEY = "75BD2E98AC17564B2DB7C74B064F5084C6557FDDF3E4C286";  
  13.   
  14.     public static <T> T getISAGService(Class<T> serviceClass, String serviceUrl) {  
  15.   
  16.         final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();  
  17.   
  18.         factory.setServiceClass(serviceClass);  
  19.   
  20.         factory.setAddress(serviceUrl);  
  21.   
  22.         return (T) factory.create();  
  23.   
  24.     }  
  25.   
  26.     /** 
  27.      * 没有代理时,通过IMSI号查询返回FJUDB数据(只要有对象返回的时候,就说明是0,成功状态.) 
  28.      * @param IMSI 
  29.      * @return 
  30.      * @throws MalformedURLException  
  31.      * @throws Exception 
  32.      */  
  33.     private static IMSILoginResult getIMSILoginResultFromQGUDBByImsi(String imsi)  
  34.             throws MalformedURLException {  
  35.         System.setProperty("http.proxyHost""192.168.13.19");  
  36.         System.setProperty("http.proxyPort""7777");  
  37.   
  38. //      URL url = new URL(serviceUrl);  
  39. //      //          URL url = WebServiceUtil.class.getResource("/conf/AccountLogin_china.xml");  
  40. //      //          URL url = new URL("file:\\C:\\Users\\FFCS-4\\Desktop\\AccountLogin.xml");  
  41. //      QName name = new QName("http://udb.chinatelecom.com", "AccountLogin");  
  42. //      AccountLogin accountLogin = new AccountLogin(url, name);  
  43. //      AccountLoginSoap accountLoginSoap = accountLogin.getAccountLoginSoap();  
  44.           
  45.         AccountLoginSoap accountLoginSoap = getISAGService(AccountLoginSoap.class, serviceUrl);  
  46.           
  47.         String SrcSsDeviceNo = QGUDB_DEVICENO;  
  48.         String AuthSsDeviceNo = QGUDB_DEVICENO;  
  49.         String UDBTokenFlag = "0";  
  50.         String IPAddress = "218.5.99.35";  
  51.   
  52.         Date date = new Date();  
  53.         SimpleDateFormat dateFormat = new SimpleDateFormat(  
  54.                 "yyyy-MM-dd HH:mm:ss");  
  55.         String TimeStamp = dateFormat.format(date);  
  56.         String Extension = "";  
  57.         //先把各字段串成一个字符串  
  58.         String Authenticator1 = SrcSsDeviceNo + AuthSsDeviceNo + imsi  
  59.                 + UDBTokenFlag + IPAddress + TimeStamp + Extension;  
  60.         String Authenticator2 = Cryto.generateAuthenticator(Authenticator1,QGUDB_DESKEY, "utf-8");  
  61.   
  62.         IMSILoginRequest imsiLoginRequest = new IMSILoginRequest();  
  63.         imsiLoginRequest.setAuthenticator(Authenticator2);  
  64.         imsiLoginRequest.setAuthSsDeviceNo(AuthSsDeviceNo);  
  65.         imsiLoginRequest.setExtension(Extension);  
  66.         imsiLoginRequest.setIMSI(imsi);  
  67.         imsiLoginRequest.setIPAddress(IPAddress);  
  68.         imsiLoginRequest.setSrcSsDeviceNo(SrcSsDeviceNo);  
  69.         imsiLoginRequest.setTimeStamp(TimeStamp);  
  70.         imsiLoginRequest.setUDBTokenFlag(UDBTokenFlag);  
  71.         IMSILoginResponse imsiLoginResponse = accountLoginSoap.imsiLogin(imsiLoginRequest);  
  72.         IMSILoginResult imsiLoginResult = imsiLoginResponse.getIMSILoginResult();  
  73.   
  74.         IMSILoginResult result = null;  
  75.         //如果返回状态为0时,说明查询成功  
  76.         if (imsiLoginResult.getResultCode() == 0) {  
  77.             result = imsiLoginResult;  
  78.         }  
  79.   
  80.         return result;  
  81.     }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值