cfx将xfire收购,所以xfire的webService不会再有更新。不推荐使用。axis2的调用方式多样,不过都不简单。而且一个项目里面axis2与cfx不能合用,因为会引起jar冲突。
org.apache.ws.commons.schema.XmlSchemaCollection.read(Lorg/w3c/dom/Document;Ljava/lang/String;)Lorg/apache/ws/commons/schema/XmlSchema;
推荐使用cfx实现webService调用。
1、使用maven引入cfx需要的包
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>${jackson.version}</version>
</dependency>
2、web.xml配置如下
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
3、application.xml文件配置如下
<!-- 引入cfx实现webservice -->
<import resource="classpath*:META-INF/cxf/cxf.xml" />
<!-- 引入 soap的配置文件,这个是开发者自己书写的文件 -->
<import resource="classpath*:xml/webservice/cfx/beans-soap.xml" />
<!--beans-soap文件内容
如下
-->
<?xml version="1.0" encoding="UTF-8"?>
<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 http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<!--id要保证不唯一,address是要访问的方法名字,implementor是指向的类-->
<jaxws:endpoint id="userValidate" address="/userValidateByParam"
implementor="com.webservice.cfx.UserValidateImpl" />
</beans>
4、创建接口
IUserValidate
@WebService
public interface IUserValidate {
public String validateUser(String message);
}
创建实现类UserValidateImpl
@WebService(endpointInterface = "com.webservice.cfx.IUserValidate")
public class UserValidateImpl implements IUserValidate {
@Override
public String validateUser(String message){
return "第三个webService";
}
}
5、java调用
@Override
public void webServiceCFX(){
logger.info("cfx方式调用WebService接口");
JaxWsProxyFactoryBean svr = new JaxWsProxyFactoryBean();
svr.setServiceClass(IUserValidate.class);
svr.setAddress("http://localhost:8080/springInstanceThree/service/userValidateByParam?wsdl");
IUserValidate hw = (IUserValidate) svr.create();
String str=hw.validateUser("<?xml version=\"1.0\" encoding=\"UTF-8\"?>传过去了第三份的部署</xml>");
System.out.println("返回的字符串:"+str);
}
调用完成