加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

客户端几种取WebServices中数据

发布时间:2020-12-17 01:27:38 所属栏目:安全 来源:网络整理
导读:1、? ??? ?String urlString = "http://127.0.0.1:9000/onlinewebservices/services/userinfo?wsdl"; ??? ?try { ??? ??URL url = new URL(urlString); ??? ??Client mClient = new Client(url); ??? ?? ??? ??mClient.addOutHandler(new DOMOutHandler());

1、?
??? ?String urlString = "http://127.0.0.1:9000/onlinewebservices/services/userinfo?wsdl";
??? ?try {
??? ??URL url = new URL(urlString);
??? ??Client mClient = new Client(url);
??? ??
??? ??mClient.addOutHandler(new DOMOutHandler());
??? ??Properties properties = new Properties();
??? ??
??? ??properties.setProperty(WSHandlerConstants.ACTION,WSHandlerConstants.USERNAME_TOKEN);
??? ??properties.setProperty(WSHandlerConstants.PASSWORD_TYPE,WSConstants.PW_DIGEST);
??? ??properties.setProperty(WSHandlerConstants.USER,"wcl");
??? ??properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,UserPaswdHandler.class.getName());
??? ??mClient.addOutHandler(new WSS4JOutHandler(properties));
??? ??
??? ??
??? ??//mClient.addOutHandler(new ClientAuthenticationHandler("wcl","0"));
??? ??Object[] mObj = mClient.invoke("queryUserInfoCnt",new Object[]{null});
??? ??System.out.println(mObj[0].toString());

?

2、

package com.njty.service;


import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.util.Properties;

import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.client.XFireProxy;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.security.wss4j.WSS4JOutHandler;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.codehaus.xfire.util.dom.DOMOutHandler;

import com.njty.bean.UserBean;

public class webserviceClientTest {
?private ObjectServiceFactory serviceFactory;
?private XFireProxyFactory proxyFactory;
?private Service service;
?private? UserInfoService userService;
?
?private String url="http://127.0.0.1:9000/onlinewebservices/services/userinfo";
?
?public webserviceClientTest() {
??serviceFactory=new ObjectServiceFactory();
??proxyFactory=new XFireProxyFactory();
?}
?
?public static void main(String[] args) {
??webserviceClientTest uc=new webserviceClientTest();
??
?? uc.initService();
?? UserBean _paramBean = new UserBean();
?? _paramBean.setUserId(10);
??
?? //uc.userService.queryUserInfoById(bean);
??
??try {
???
???UserBean mUserBean =? uc.userService.queryUserInfoById(_paramBean);
???
???System.out.println(mUserBean.getUserName());
???
??} catch (Exception e) {
???e.printStackTrace();
??}
?}

?private void initService(){
??service=serviceFactory.create(UserInfoService.class);
??
??
??try {
???
???userService=(UserInfoService)proxyFactory.create(service,url);
???Client mClient = ((XFireProxy)Proxy.getInvocationHandler(userService)).getClient();

???mClient.addOutHandler(new DOMOutHandler());??? ??Properties properties = new Properties();??? ????? ??properties.setProperty(WSHandlerConstants.ACTION,WSHandlerConstants.USERNAME_TOKEN);??? ??properties.setProperty(WSHandlerConstants.PASSWORD_TYPE,WSConstants.PW_DIGEST);??? ??properties.setProperty(WSHandlerConstants.USER,"wcl");??? ??properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,UserPaswdHandler.class.getName());??? ??mClient.addOutHandler(new WSS4JOutHandler(properties));?????} catch (MalformedURLException e) {???System.out.println("服务获取失败...");???e.printStackTrace();??}??System.out.println("服务获取成功...");?}}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读