java xfire+ spring 发布服务端web service 以及客户端调用
发现,在客户端调用 结合spring的时候,
log中打印出:Retrieving document at 'null'.
目前属于 xfire的一个bug,xfire版本:1.2.6.
http://jira.codehaus.org/browse/XFIRE-1088
从bug上 还没有看到相应的fix的版本。
====================================
服务端 编写:
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
<!-- ====================testSpringXfire================= -->
<bean id="senderMsgWs" />
<bean id="helloWs" />
<bean id="addressingHandler"
/>
<bean name="senderMsgWsWebService"
ref="senderMsgWs"></property>
<property name="serviceClass" value="com.mjp.ws.ISenderMsgWs"></property>
<property name="inHandlers">
<list>
<ref bean="addressingHandler" />
</list>
</property>
</bean>
<bean name="helloWsWebService"
ref="helloWs"></property>
<property name="serviceClass" value="com.mjp.ws.IHelloWs"></property>
<property name="inHandlers">
<list>
<ref bean="addressingHandler" />
</list>
</property>
</bean>
-------------------------------
通过web url
http://localhost:8080/xfiremsg/services
可以看到发布的webservice。
客户端调用:
-------------
1.spring:结合:
<bean id="wsService" lazy-init="false" abstract="true"/>
<bean id="helloService" parent="wsService">
<property name="serviceClass">
<value>com.mjp.ws.client.IHelloWs</value>
</property>
<property name="wsdlDocumentUrl">
<value>http://localhost:8080/xfiremsg/services/IHelloWs?wsdl</value>
</property>
</bean>
private static void run1() {
System.out.println("-------run1 start-------------------");
try {
Service serviceModel = new ObjectServiceFactory()
.create(IHelloWs.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String url = "http://localhost:8080/xfiremsg/services/IHelloWs";
IHelloWs cws = (IHelloWs) factory.create(serviceModel, url);
String result = cws.hello("mjp");
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("-------run1 end-------------------");
}
private static void run2() {
System.out.println("-------run2 start-------------------");
try {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml");
IHelloWs cws = (IHelloWs) ctx.getBean("helloService");
String result = cws.hello("mjp");
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("-------run2 end-------------------");
}
----------------------------
客户端调用时 :首先将 发布服务的接口,输入参数对象,返回对象对于的自定义类,接口类,打成一个jar,加入到工程里边