提问人:Johan 提问时间:11/8/2023 更新时间:11/8/2023 访问量:16
SOAP 请求元素名称与 WSDL 中的名称不同
SOAP request element name not the same as in WSDL
问:
我从第三方导入了 WSDL,并使用 IntelliJ 生成了 Java 类。当我发送 SOAP 请求时,XML 中的名称与 WSDL 中定义的名称不对应。
使用工具(如 SoapUI)可以正常导入 XML 并且元素名称符合预期。
看起来编组忽略了@XmlElementRef注释并使用变量类型。
这是我所期望的:
<rxh2:Documents>
<rxh2:Document>
<rxh2:Base64String>JVBERi0xLjQN</rxh2:Base64String>
<rxh2:DocumentType>Pdf</rxh2:DocumentType>
</rxh2:Document>
</rxh2:Documents>
但是,我的 XML 是这样的 - 为什么它被称为 ArrayOfDocument 而不是 Documents?
<ns2:ArrayOfDocument>
<ns2:Document>
<ns2:Base64String>JVBERi0xLjYKJbiakp0KMS</ns2:Base64String>
<ns2:DocumentType>Pdf</ns2:DocumentType>
</ns2:Document>
</ns2:ArrayOfDocument>
在我的 pom.xml 中导入 WSDL 的设置定义如下:
<plugin>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>4.0.2</version>
<configuration>
<wsdlUrls>
<wsdlUrl>
https://thewebsite/Integration/Service.OrderService.svc?wsdl
</wsdlUrl>
</wsdlUrls>
<extension>true</extension>
<verbose>true</verbose>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
</configuration>
<executions>
<execution>
<id>endpoint.hpc</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>com.cgm.ms.script</packageName>
<args>
<arg>-B-XautoNameResolution</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
查看生成的代码,我看到以下内容:
@XmlElementRef(name = "Documents", namespace = "http://schemas.datacontract.org/2010/12/Service.Models.RFM", type = JAXBElement.class, required = false)
protected JAXBElement<ArrayOfDocument> documents;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfDocument", propOrder = {
"document"
})
public class ArrayOfDocument {
@XmlElement(name = "Document", nillable = true)
protected List<Document> document;
...
}
答:
0赞
Johan
11/8/2023
#1
最后,我们需要做的就是更改 ObjectFactory.java 文件。我们将 localPart 从 ArrayOfDocument 更改为 Documents,现在我们的 xml 是 100%。
private static final QName _ArrayOfDocument_QNAME = new QName("http://schemas.datacontract.org/2010/12/Service.Models.RFM", "Documents");
结果:
<ns2:Documents>
<ns2:Document>
<ns2:Base64String>JVBERi0xLjYKJbiakp0KMSAwIG9iajw8L1B=</ns2:Base64String>
<ns2:DocumentType>Pdf</ns2:DocumentType>
</ns2:Document>
</ns2:Documents>
评论