axis调用cxf发布的WebService服务
cxf发布WebService服务
WebServiceConfig.java
@Configuration
public class WebServiceConfig{
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus(){
return new SpringBus();
}
@Bean
public TestService testService(){
return new TestServiceImpl();
}
@Bean
public Endpoint endpoint(){
Endpoint endpoint = new EndpointImpl(SpringBus(), exchangeStandard());
endpoint.publish("/ws/service");
return endpoint;
}
}
TestService.java
@WebService(name = "Test", targetNamespace = "http://,,,.com")
public interface TestService{
@WebResult("result")
@WebMethod(action = "http://,,,.com/test1")
public String test1(
@WebParam(name = "name")String name,
@WebParam(name = "name1")int name1,
@WebParam(name = "name2")byte[] name2);
@WebResult("result")
@WebMethod(action = "http://,,,.com/test2")
public String test2(
@WebParam(name = "name3")String name3);
}
TestServiceImpl.java
@WebService(endpointInterface = "包名.TestService", targetNamespace = "http://,,,.com", serviceName = "Test")
public class TestServiceImpl implements TestService{
@Override
public String test1(String name, int name1, byte[] name2){
return "test1"
}
@Override
public String test2(String name3){
return "test2";
}
}
在application.yml上配置:
cxf:
path:
/test
输入http://ip:port/test/ws/service?esdl会展示发布的服务
axis调用cxf发布的服务
String nameSpace = "http://,,,.com";
String address = "http://ip:port/test/ws/service";
Service service = new Service();
try{
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new URL(address));
call.setOperationName(new QName(nameSpace),"test1");
call.addParameter("name", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("name1",XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("name2",XMLType.XSD_STRING, ParameterMode.IN);
// 如果不加returnType会提示no returntype was specified to the Call object
call.setReturnType(XMLType.XSD_STRING);
Object result = call.invoke(new Object[]{"nameValue", "name1Value", "name2Value"})
}
需要导入的依赖
依赖如果缺少,会报错
1、The type javax.xml.rpc.ServiceException cannot be resolved. It is indirectly referenced from require
2、org.apache.commons.discovery.tools.DiscoverSingleton
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
</dependency>