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("服务获取成功..."); }}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。