SOAP端点必须返回字符串值

时间:2018-09-25 10:02:27

标签: web-services spring-boot soap soapui

我是SOAP技术的新手,

我只想测试此端点:

我的java文件:

@Endpoint
public class DestinataireEndpoints {

    private static final String NAMESPACE_URI = "http://www.opensolution.com/";

    @Autowired
    private DestinataireService destinataireService;    

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "LiaisonResponse")
    @ResponsePayload
    public String LiaisonResponse() {
        return "SAMPLE";
    }

我的xsd文件:

<xs:element name="LiaisonResponse">
       <xs:complexType>
         <xs:sequence>
           <xs:element minOccurs="0" maxOccurs="1" name="LiaisonResult" type="xs:string" />
         </xs:sequence>
       </xs:complexType>
     </xs:element>

这是我的配置文件:

@EnableWs
@Configuration
public class SoapConfig 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 = "destinataire")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema statesSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("StatesPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://www.opensolution.com/");
        wsdl11Definition.setSchema(statesSchema);
        return wsdl11Definition;
    }

    @Bean
    public XsdSchema statesSchema() {
        return new SimpleXsdSchema(new ClassPathResource("destinataire.xsd"));
    }

我使用SoapUI进行测试,这就是我得到的:

enter image description here

缺少什么?

1 个答案:

答案 0 :(得分:0)

好,我明白!

我的xsd中有两个元素:

 <xs:element name="Liaison">
       <xs:complexType />
 </xs:element>
 <xs:element name="LiaisonResponse">
    <xs:complexType>
       <xs:sequence>
         <xs:element minOccurs="0" maxOccurs="1" name="LiaisonResult" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
 </xs:element>

我已经更改了EndPoint:

@Endpoint
public class DestinataireEndpoints {

    private static final String NAMESPACE_URI = "http://www.opensolution.com/";

    @Autowired
    private DestinataireService destinataireService;    

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "Liaison")
    @ResponsePayload
    public LiaisonResponse Liaison() {
        LiaisonResponse liaisonResponse = new LiaisonResponse();
        liaisonResponse.setLiaisonResult("tests");
        return liaisonResponse;
    }

我收到一个“ Liaison”元素,并返回一个LiaisonResponse元素 然后我将liaisonResult属性设置为String值