How to send a SOAP request using WebServiceTemplate?

前端 未结 5 792
温柔的废话
温柔的废话 2020-11-30 07:50

I am trying to send a request to a SOAP webservice. I read this tutorial and prepared the following code. However, I am going to send different requests to multiple SOAP web

5条回答
  •  一生所求
    2020-11-30 08:17

    You can use following code, you do not need to define anything in xml file.

      try {
                SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(
                        MessageFactory.newInstance());
                messageFactory.afterPropertiesSet();
    
                WebServiceTemplate webServiceTemplate = new WebServiceTemplate(
                        messageFactory);
                Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    
                marshaller.setContextPath("PACKAGE");
                marshaller.afterPropertiesSet();
    
                webServiceTemplate.setMarshaller(marshaller);
                webServiceTemplate.afterPropertiesSet();
    
                Response response = (Response) webServiceTemplate
                        .marshalSendAndReceive(
                                "address",
                                searchFlights);
    
                Response msg = (Response) response;
            } catch (Exception s) {
                s.printStackTrace();
            }
    

提交回复
热议问题