发布CXF时遇到一个问题,发布的服务,wsdl文件中没有<wsdl:types/><wsdl:message/>标签,wsdl文件如下:
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:xsd="/2001/XMLSchema" xmlns:wsdl="/wsdl/" xmlns:tns="com.oristartech.sms.core.ws.server" xmlns:soap="/wsdl/soap/" xmlns:ns2="/soap/http" xmlns:ns1="http://server.ws.core./" name="dispatchService" targetNamespace="com.oristartech.sms.core.ws.server"><wsdl:import location="http://localhost:8080/sms/webservice/isSwitch?wsdl=DispatchService.wsdl" namespace="http://server.ws.core./"></wsdl:import><wsdl:binding name="dispatchServiceSoapBinding" type="ns1:DispatchService"><soap:binding style="document" transport="/soap/http"/><wsdl:operation name="isSwitchHall"><soap:operation soapAction="" style="document"/><wsdl:input name="isSwitchHall"><soap:body use="literal"/></wsdl:input><wsdl:output name="isSwitchHallResponse"><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="dispatchService"><wsdl:port binding="tns:dispatchServiceSoapBinding" name="DispatchServiceImplPort"><soap:address location="http://localhost:8080/sms/webservice/isSwitch"/></wsdl:port></wsdl:service></wsdl:definitions>
对比别的wsdl文件,发现多了 wsdl:import,将其地址复制到浏览器地址栏,发现里面是丢失的两个标签,这才发现不是丢失,而是包含在wsdl:import标签里面。
仔细查找原因:实现类中标明了命名空间@WebService(targetNamespace=“com.oristartech.sms.core.ws.server"),接口类未标明命名空间(@WebService())
解决方案:将接口类和实现类标注命名空间,两者保持一致即可。
接口类代码:
@WebService(targetNamespace = "com.oristartech.sms.core.ws.server")public interface DispatchService {public String isSwitchHall(@WebParam(name="isSwitch")String isSwitch);}
实现类代码:
@WebService(endpointInterface = "com.oristartech.sms.core.ws.server.DispatchService", targetNamespace = "com.oristartech.sms.core.ws.server", serviceName="dispatchService")public class DispatchServiceImpl implements DispatchService {public String isSwitchHall(@WebParam(name="isSwitch")String isSwitch) {System.out.println("===="+isSwitch);return "111";}}