首页 > 解决方案 > Spring Webservice - 直接在 SOAP 消息体上发送属性而不被包装在类上

问题描述

我想知道是否有人可以帮助我。

我必须用这种结构调用一个 SOAP 端点:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ese="http://tsp-gate.globaltrustedsign.com/ESealPdf">
   <soapenv:Header/>
   <soapenv:Body>
      <ese:Digest>YYYYYY</ese:Digest>
      <ese:Certificate>xxxxx</ese:Certificate>
   </soapenv:Body>
</soapenv:Envelope>

就像您可以看到字段直接位于 SOAP 主体的根部一样。

我正在使用 Spring WebserviceTemplate 发出请求。我也在生成基于 WSDL 的类,但它只是生成这个:

@XmlRegistry
public class ObjectFactory {

    private final static QName _Digest_QNAME = new QName("http://tsp-gate.globaltrustedsign.com/ESealPdf", "Digest");
    private final static QName _Certificate_QNAME = new QName("http://tsp-gate.globaltrustedsign.com/ESealPdf", "Certificate");
    private final static QName _Signature_QNAME = new QName("http://tsp-gate.globaltrustedsign.com/ESealPdf", "Signature");


    public ObjectFactory() {
    }


    @XmlElementDecl(namespace = "http://tsp-gate.globaltrustedsign.com/ESealPdf", name = "Digest")
    public JAXBElement<String> createDigest(String value) {
        return new JAXBElement<String>(_Digest_QNAME, String.class, null, value);
    }

    @XmlElementDecl(namespace = "http://tsp-gate.globaltrustedsign.com/ESealPdf", name = "Certificate")
    public JAXBElement<String> createCertificate(String value) {
        return new JAXBElement<String>(_Certificate_QNAME, String.class, null, value);
    }


    @XmlElementDecl(namespace = "http://tsp-gate.globaltrustedsign.com/ESealPdf", name = "Signature")
    public JAXBElement<String> createSignature(String value) {
        return new JAXBElement<String>(_Signature_QNAME, String.class, null, value);
    }

}

现在,我不知道如何基于此构建请求,在某种程度上我可以使用方法 webServiceTemplate.marshalSendAndReceive()。

我还想了解 webserviceTemplate + JaxbMarshaller 是否只允许或限制创建包装在对象实例中的 XML 请求(用 @XmlRootElement 注释)。

标签: javaspringsoapjaxb

解决方案


推荐阅读