CXF发布服务,WebService缺少<wsdl:types/><wsdl:message/>标签

来源:互联网 发布:孙叔敖之知 编辑:程序博客网 时间:2024/05/06 04:45

发布CXF时遇到一个问题,发布的服务,wsdl文件中没有<wsdl:types/><wsdl:message/>标签,wsdl文件如下:

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"   xmlns:tns="com.oristartech.sms.core.ws.server" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"   xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://server.ws.core.sms.oristartech.com/"   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.sms.oristartech.com/">    </wsdl:import>  <wsdl:binding name="dispatchServiceSoapBinding" type="ns1:DispatchService">    <soap:binding style="document" transport="http://schemas.xmlsoap.org/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";}}