1

我正在努力使用开放的假装客户端正确发出 SOAP 请求并获得响应。出于测试目的,我采用了这个公共 SOAP 服务http://www.learnwebservices.com/这是 WSDL -> http://www.learnwebservices.com/services/hello?WSDL

我从这个 WSDL 生成了如下所示的类:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SayHello", propOrder = {
    "helloRequest"
})
public class SayHello {

    @XmlElement(name = "HelloRequest", required = true)
    protected HelloRequest helloRequest;

//getters and setters
}


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "helloRequest", propOrder = {
    "name"
})
public class HelloRequest {

    @XmlElement(name = "Name", required = true)
    protected String name;
//getters and setters
}

我试着按照这个例子:

如何使用 FEIGN 客户端发送 SOAP 对象?

基本上我创建了这个伪装配置:

private static final JAXBContextFactory jaxbContextFactory = new JAXBContextFactory.Builder()
        .withMarshallerJAXBEncoding("UTF-8")
        .withMarshallerSchemaLocation("http://www.learnwebservices.com/services/hello?WSDL")
        .build();

@Bean
public Decoder feignDecoder() {
    return new SOAPDecoder(jaxbContextFactory);
}

@Bean
public Encoder feignEncoder() {
    return new SOAPEncoder(jaxbContextFactory);
}

然后在这里我尝试像这样调用端点:

@FeignClient(name = "feign-example",
        url = "http://www.learnwebservices.com/services/hello",
        configuration = FeignConfig.class)
public interface WogSeb20FeignClient {
    @PostMapping(value = "", consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
    HelloResponse get(@RequestBody HelloRequest addRequest);
}

首先,当我尝试进行调用时,我收到错误消息,提示 HelloRequest 缺少 XmlRootElement,因此我将该注释添加到类中(即使我不确定要放置什么作为根元素,我只是在类顶部添加了 @XmlRootElement。之后,当我创建请求时,我收到此错误:

Error during parsing response data. Status: 500, Cause: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Message part helloRequest was not recognized.  (Does it exist in service WSDL?)</faultstring></soap:Fault></soap:Body></soap:Envelope>

显然我做错了什么,有人可以给我一些指导,因为我找不到太多关于这个主题的材料。

4

0 回答 0