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("服务获取成功...");?}}