WebServiceTransportException:404

时间:2018-02-01 09:46:23

标签: web-services soap wsdl client spring-ws

我阅读了大量的论坛,但我没有为我找到解决方案 我想实现SOAP客户端并向SOAP服务器发送请求 当我从SOAP UI发送请求时,我会得到回应 但是如果我从客户端代码发送请求,我在客户端有例外:

org.springframework.ws.client.WebServiceTransportException:  [404]  at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:699) at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:609)    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:383) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:373)    

我在服务器端也有WARN No endpoint mapping found for [SaajSoapMessage {http://www.niso.org/schemas/sushi}ReportRequest]

服务器实施:

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
       // servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }

    @Bean(name = "counter_sushi4_0")
    public Wsdl11Definition defaultWsdl11Definition() {
        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("/xsd/count4_0/counter_sushi4_0.wsdl"));
        return wsdl11Definition;
    }

}
@Endpoint
public class SushiEndpoint {
    @PayloadRoot(namespace = "http://www.niso.org/schemas/sushi/counter", localPart = "ReportRequest")
    @ResponsePayload
    public JAXBElement<CounterReportResponse> ReportRequest(@RequestPayload JAXBElement<ReportRequest> requestJAXB){
        ObjectFactory factory = new ObjectFactory();
        CounterReportResponse response = factory.createCounterReportResponse();
        ReportRequest request = requestJAXB.getValue();
        response.setID(request.getID());
        return factory.createReportResponseCounterSushi(response);
    }
}

客户端实施:

private CounterReportResponse sendSoapRequest(JAXBElement<ReportRequest> req) {
        String URL = "http://localhost:8080/ws/counter_sushi4_0/ReportRequest";
        String PATH_TO_JAXB_CLASSES_4_0 ="com.iii.reports.generated.counter4_0";
        Jaxb2Marshaller jaxb2Marshaller_1 = new Jaxb2Marshaller();
        jaxb2Marshaller_1.setContextPath(PATH_TO_JAXB_CLASSES_4_0);  

        Jaxb2Marshaller jaxb2Marshaller_2 = new Jaxb2Marshaller();
        jaxb2Marshaller_2.setContextPath(PATH_TO_JAXB_CLASSES_4_0);  

        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        webServiceTemplate.setMarshaller(jaxb2Marshaller_1);
        webServiceTemplate.setUnmarshaller(jaxb2Marshaller_2);
        webServiceTemplate.setDefaultUri(URL);    

        JAXBElement<CounterReportResponse> responseJAXB = null;
        responseJAXB = (JAXBElement<CounterReportResponse>) webServiceTemplate.marshalSendAndReceive(req);
        CounterReportResponse response = responseJAXB.getValue();
        return response;
    }

WSDL:

<definitions xmlns:tns="SushiService"
             xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:sc="http://www.niso.org/schemas/sushi/counter"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             name="SushiService"
             targetNamespace="SushiService"
             xmlns="http://schemas.xmlsoap.org/wsdl/">
   <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>

   <types>
      <xsd:schema>
         <xsd:import schemaLocation="counter_sushi4_0.xsd"
                     namespace="http://www.niso.org/schemas/sushi/counter"/>
      </xsd:schema>
   </types>

   <message name="GetReportIn">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
      <part name="messagePart"
            element="sc:ReportRequest"/>
   </message>

   <message name="GetReportOut">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
      <part name="messagePart"
            element="sc:ReportResponse"/>
   </message>

   <portType name="SushiServiceInterface">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>

      <operation name="GetReport">
         <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
         <input message="tns:GetReportIn"/>
         <output message="tns:GetReportOut"/>
      </operation>

   </portType>

   <binding name="SushiService"
            type="tns:SushiServiceInterface">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="GetReport">
         <soap:operation soapAction="SushiService:GetReportIn"
                         style="document"/>
         <input>
            <soap:body use="literal"/>
         </input>
         <output>
            <soap:body use="literal"/>
         </output>
      </operation>
   </binding>

   <binding name="SushiServiceSoap12"
            type="tns:SushiServiceInterface">
      <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="GetReport">
         <soap12:operation soapAction="SushiService:GetReportIn"
                           style="document"/>
         <input>
            <soap12:body use="literal"/>
         </input>
         <output>
            <soap12:body use="literal"/>
         </output>
      </operation>
   </binding>

   <service name="SushiService">
      <port name="SushiServicePort"
            binding="tns:SushiService">
         <soap:address location=""/>
      </port>
   </service>

</definitions>

1 个答案:

答案 0 :(得分:0)

解决方案很简单。 注意你的命名空间 端点具有命名空间:

namespace = "http://www.niso.org/schemas/sushi/counter"  

ReportCounter类有命名空间

namespace = "http://www.niso.org/schemas/sushi"  

他们应该等于