我正在使用apache cxf 2.7.8,并且正在使用cxf-codegen-plugin生成类。 我的问题是cxf在请求中使用了错误的名称空间。
这是理想的要求:
<soap:Body>
<ns3:ImportFile xmlns="http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts" xmlns:ns2="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" xmlns:ns3="http://fakeaddress.hu/" xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/">
<ns3:fileImportRequest>
<FileContent>cid:7f626b0b-d398-4513-8195-6752d0592807-1</FileContent>
<FileHash>3b1e9401209858c408103ded300e665c</FileHash>
<FileName>xml_1556265450288.zip</FileName>
</ns3:fileImportRequest>
</ns3:ImportFile>
这就是我现在得到的:
<soap:Body>
<ns3:ImportFile xmlns="http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts" xmlns:ns2="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" xmlns:ns3="http://fakeaddress.hu/" xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/">
<ns3:fileImportRequest>
<ns4:base64Binary>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:ae4bba67-cb07-4740-9418-d12d04108b0b-1@schemas.microsoft.com"/>
</ns4:base64Binary>
<ns4:string>3b1e9401209858c408103ded300e665c</ns4:string>
<ns4:string>xml_1556265450288.zip</ns4:string>
</ns3:fileImportRequest>
</ns3:ImportFile>
以某种方式cxf使用“ http://schemas.microsoft.com/2003/10/Serialization/”命名空间而不是“ NDDWH.Model.Contracts”命名空间。 因此,它显示的不是“ FileHash”,而是“ ns4:string”。
我有以下wsdl代码段:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType" />
<xs:element name="anyURI" nillable="true" type="xs:anyURI" />
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
<xs:element name="boolean" nillable="true" type="xs:boolean" />
<xs:element name="byte" nillable="true" type="xs:byte" />
<xs:element name="dateTime" nillable="true" type="xs:dateTime" />
<xs:element name="decimal" nillable="true" type="xs:decimal" />
<xs:element name="double" nillable="true" type="xs:double" />
<xs:element name="float" nillable="true" type="xs:float" />
<xs:element name="int" nillable="true" type="xs:int" />
<xs:element name="long" nillable="true" type="xs:long" />
<xs:element name="QName" nillable="true" type="xs:QName" />
<xs:element name="short" nillable="true" type="xs:short" />
<xs:element name="string" nillable="true" type="xs:string" />
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
<xs:element name="char" nillable="true" type="tns:char" />
<xs:simpleType name="char">
<xs:restriction base="xs:int" />
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration" />
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
<xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
<xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid" />
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName" />
<xs:attribute name="Id" type="xs:ID" />
<xs:attribute name="Ref" type="xs:IDREF" />
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts">
<xs:import namespace="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" />
<xs:complexType name="FileImportRequestContract">
<xs:sequence>
<xs:element minOccurs="0" name="FileContent" nillable="true" type="xs:base64Binary" />
<xs:element minOccurs="0" name="FileHash" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="FileName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Id" type="xs:long" />
<xs:element minOccurs="0" name="OpFlag" nillable="true" type="xs:string" />
<xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" minOccurs="0" name="OpMessages" nillable="true" type="q1:ArrayOfContractMessage" />
</xs:sequence>
</xs:complexType>
<xs:element name="FileImportRequestContract" nillable="true" type="tns:FileImportRequestContract" />
<xs:complexType name="FileImportResponseContract">
<xs:sequence>
<xs:element minOccurs="0" name="Id" type="xs:long" />
<xs:element minOccurs="0" name="Message" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="OpFlag" nillable="true" type="xs:string" />
<xs:element xmlns:q2="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" minOccurs="0" name="OpMessages" nillable="true" type="q2:ArrayOfContractMessage" />
<xs:element minOccurs="0" name="Success" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
<xs:element name="FileImportResponseContract" nillable="true" type="tns:FileImportResponseContract" />
</xs:schema>
生成的请求类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FileImportRequestContract", propOrder = {
"fileContent",
"fileHash",
"fileName",
"id",
"opFlag",
"opMessages"
})
public class FileImportRequestContract {
@XmlElementRef(name = "FileContent", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<byte[]> fileContent;
@XmlElementRef(name = "FileHash", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<String> fileHash;
@XmlElementRef(name = "FileName", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<String> fileName;
@XmlElement(name = "Id")
protected Long id;
@XmlElementRef(name = "OpFlag", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<String> opFlag;
@XmlElementRef(name = "OpMessages", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<ArrayOfContractMessage> opMessages;
生成的类对我来说没问题。设置了正确的名称空间,并且XmlElementRefs具有正确的名称。当cxf尝试从Java代码中制作肥皂主体时,就会发生问题。有想法吗?