`

cxf做web Service,axis2做客户端调用的demo

 
阅读更多
步骤
一.建立Web Service服务
1.导入cxf框架到WebService项目中.
2.建立功能性Interface
3.新建类Impl,实现2中接口的方法.
   (逻辑部分)
4.新建startWebService类,其中main方法
	public static void main(String[] args) {

		JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
		factory.setServiceClass(doSayHelloImpl.class);
		factory.setAddress("http://localhost:8080/doXXX");
		
		Server server = factory.create();
		server.start();
	}


5.run as Java application

二.客户端调用Web Service服务
1.导入axis2框架到Client项目中
2.wsdl2java 逆向 web Service的调用接口
3.建立测试用的类
main方法
	public static void main(String[] args) throws RemoteException {
		// TODO Auto-generated method stub
		DoSayHelloImplServiceStub dhello = new DoSayHelloImplServiceStub();
		
		DoSayHelloImplServiceStub.DoSayHelloE de = new DoSayHelloImplServiceStub.DoSayHelloE();
		DoSayHello ds = new DoSayHello();
		ds.setArg0("macleo");
		de.setDoSayHello(ds);
		String  result = dhello.doSayHello(de).getDoSayHelloResponse().get_return();
		out.println(result);
	}


4.run as Java application

5.会看到简单的 "你好,macleo"的调用结果.

分享到:
评论
2 楼 macleo 2013-09-14  
cherryzhu 写道
你好,我的程序就是按你说的这种情况写的,但是在客户端调用时抛异常:
Exception in thread "main" org.apache.axis2.AxisFault: The given SOAPAction http://bean.server.com/IHelloService/getHello does not match an operation.
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.client.jaxws.IHelloServiceServiceStub.getHello(IHelloServiceServiceStub.java:331)
at com.client.test.HelloClientTest.main(HelloClientTest.java:19)

请问这是什么原因,谢谢。

貌似少这个:ds.setArg0("macleo"); 
1 楼 cherryzhu 2013-09-13  
你好,我的程序就是按你说的这种情况写的,但是在客户端调用时抛异常:
Exception in thread "main" org.apache.axis2.AxisFault: The given SOAPAction http://bean.server.com/IHelloService/getHello does not match an operation.
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.client.jaxws.IHelloServiceServiceStub.getHello(IHelloServiceServiceStub.java:331)
at com.client.test.HelloClientTest.main(HelloClientTest.java:19)

请问这是什么原因,谢谢。

相关推荐

Global site tag (gtag.js) - Google Analytics