第一步,测试wsdl:
访问 :8080/项目路径/services/spring cxf配置文件中的address?wsdl,例如::8080/abc/services/WorkUnitInfo?wsdl
第二步:测试webservice
1、WebService 客户端 spring 配置文件 wsclient-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/schema/jaxws.xsd">
<bean
factory-bean="workUnitInfoFactory" factory-method="create">
</bean>
<bean>
<property value="com.cslc.crius.common.ws.cxf.server.IWorkUnitInfo"/>
<property value="http://localhost:8080/viminal/services/WorkUnitInfo?wsdl"></property>
</bean>
</beans>
<!-- END SNIPPET: beans -->
2、调用WebService接口的测试程序
package com.cxf.client;
import java.util.Date;
import java.util.List;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.cslc.crius.common.utils.DateUtils;
import com.cslc.crius.common.ws.cxf.server.IWorkUnitInfo;
import com.cslc.crius.viminal.vo.WorkUnitVO;
public final class Client {
private Client() {
}
public static void main(String args[]) throws Exception {
// START SNIPPET: client
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext(new String[] {"client/wsclient-context.xml"});
IWorkUnitInfo work = (IWorkUnitInfo)context.getBean("workUnitInfoClient");
Date date = DateUtils.parseDate("2012-10-01");
List<WorkUnitVO> r = work.getWorkUnitByDate(date);
for (int i=0;i<r.size();i++) {
System.out.println(r.get(i).getWorkUnitTitle());
}
System.exit(0);
// END SNIPPET: client
}
}
基本步骤就是上面这些,对外提供的接口就是上面测试wsdl所用的url。