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

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服务端已经部署完毕)

	public static void main(String[] args) throws MalformedURLException {
		
		System.out.println("start.");
		IMSILoginResult login = getIMSILoginResultFromQGUDBByImsi("460030136905408");
		System.out.println("mobile is " + login.getUserID());
		
	}

	private static String serviceUrl = "http://sersh.passport.189.cn/UDBAPPInterface/UDBAPPSYS/AccountLogin.asmx?WSDL";

	private static String QGUDB_DEVICENO = "3500000000408501";
	private static String QGUDB_DESKEY = "75BD2E98AC17564B2DB7C74B064F5084C6557FDDF3E4C286";

	public static  T getISAGService(Class serviceClass, String serviceUrl) {

		final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

		factory.setServiceClass(serviceClass);

		factory.setAddress(serviceUrl);

		return (T) factory.create();

	}

	/**
	 * 没有代理时,通过IMSI号查询返回FJUDB数据(只要有对象返回的时候,就说明是0,成功状态.)
	 * @param IMSI
	 * @return
	 * @throws MalformedURLException 
	 * @throws Exception
	 */
	private static IMSILoginResult getIMSILoginResultFromQGUDBByImsi(String imsi)
			throws MalformedURLException {
		System.setProperty("http.proxyHost", "192.168.13.19");
		System.setProperty("http.proxyPort", "7777");

//		URL url = new URL(serviceUrl);
//		//			URL url = WebServiceUtil.class.getResource("/conf/AccountLogin_china.xml");
//		//			URL url = new URL("file:\\C:\\Users\\FFCS-4\\Desktop\\AccountLogin.xml");
//		QName name = new QName("http://udb.chinatelecom.com", "AccountLogin");
//		AccountLogin accountLogin = new AccountLogin(url, name);
//		AccountLoginSoap accountLoginSoap = accountLogin.getAccountLoginSoap();
		
		AccountLoginSoap accountLoginSoap = getISAGService(AccountLoginSoap.class, serviceUrl);
		
		String SrcSsDeviceNo = QGUDB_DEVICENO;
		String AuthSsDeviceNo = QGUDB_DEVICENO;
		String UDBTokenFlag = "0";
		String IPAddress = "218.5.99.35";

		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String TimeStamp = dateFormat.format(date);
		String Extension = "";
		//先把各字段串成一个字符串
		String Authenticator1 = SrcSsDeviceNo + AuthSsDeviceNo + imsi
				+ UDBTokenFlag + IPAddress + TimeStamp + Extension;
		String Authenticator2 = Cryto.generateAuthenticator(Authenticator1,QGUDB_DESKEY, "utf-8");

		IMSILoginRequest imsiLoginRequest = new IMSILoginRequest();
		imsiLoginRequest.setAuthenticator(Authenticator2);
		imsiLoginRequest.setAuthSsDeviceNo(AuthSsDeviceNo);
		imsiLoginRequest.setExtension(Extension);
		imsiLoginRequest.setIMSI(imsi);
		imsiLoginRequest.setIPAddress(IPAddress);
		imsiLoginRequest.setSrcSsDeviceNo(SrcSsDeviceNo);
		imsiLoginRequest.setTimeStamp(TimeStamp);
		imsiLoginRequest.setUDBTokenFlag(UDBTokenFlag);
		IMSILoginResponse imsiLoginResponse = accountLoginSoap.imsiLogin(imsiLoginRequest);
		IMSILoginResult imsiLoginResult = imsiLoginResponse.getIMSILoginResult();

		IMSILoginResult result = null;
		//如果返回状态为0时,说明查询成功
		if (imsiLoginResult.getResultCode() == 0) {
			result = imsiLoginResult;
		}

		return result;
	}


你可能感兴趣的:(java wsdl反向生成源码,并使用CXF实现客户端调用代码)