大家好我需要按照以下方式生成肥皂响应。我已将其生成到" GetTestDetailResult" node.But无法添加" country"作为根节点的子节点(GetTestDetailResponse)。
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetTestDetailResponse>
<GetTestDetailResult>
<id>string</id>
<fname>string</fname>
<lname>string</lname>
</GetTestDetailResult>
<country>string</country>
<age>int</age>
</GetTestDetailResponse>
</soap:Body>
</soap:Envelope>
我的wsdl文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="TestServiceService" targetNamespace="http://www.test.org/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://www.test.org/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.test.org/"
attributeFormDefault="unqualified"
elementFormDefault="unqualified"
targetNamespace="http://www.test.org/">
<xs:element name="GetTestDetail" type="tns:GetTestDetail"/>
<xs:element name="GetTestDetailResponse" type="tns:GetTestDetailResponse"/>
<xs:complexType name="GetTestDetail">
<xs:sequence>
<xs:element minOccurs="0" name="email" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="GetTestDetailResponse">
<xs:sequence>
<xs:element minOccurs="1" name="GetTestDetailResult" type="tns:GetTestDetailResult"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="GetTestDetailResult">
<xs:sequence>
<xs:element minOccurs="0" name="id" type="xs:string"/>
<xs:element minOccurs="0" name="fname" type="xs:string"/>
<xs:element minOccurs="0" name="lname" type="xs:string"/>
<xs:element minOccurs="0" name="authFailed" type="xs:string"/>
<xs:element minOccurs="0" name="soapMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetTestDetail">
<wsdl:part name="parameters" element="tns:GetTestDetail"/>
</wsdl:message>
<wsdl:message name="GetTestDetailResponse">
<wsdl:part name="parameters" element="tns:GetTestDetailResponse"/>
</wsdl:message>
<wsdl:portType name="TestServiceWsdlEndpointPortType">
<wsdl:operation name="GetTestDetail">
<wsdl:input name="GetTestDetail" message="tns:GetTestDetail"/>
<wsdl:output name="GetTestDetailResponse" message="tns:GetTestDetailResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestServiceWsdlEndpointBinding" type="tns:TestServiceWsdlEndpointPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetTestDetail">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="GetTestDetail">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getTestDetailResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestServiceWsdlEndpoint">
<wsdl:port name="TestServiceWsdlPort" binding="tns:TestServiceWsdlEndpointBinding">
<soap:address location="http://localhost:8080/test/services/TestServiceWsdl"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
我的响应式Java类是: -
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "testDetail", propOrder = {
"id",
"fname",
"lname"
})
public class TestDetail {
protected String id;
protected String fname;
protected String lname;
protected String authFailed;
protected String soapMessage;
public String getId() {
return id;
}
public void setId(String value) {
this.id = value;
}
public String getFname() {
return fname;
}
public void setFname(String value) {
this.fname = value;
}
public String getLname() {
return lname;
}
public void setLname(String value) {
this.lname = value;
}
public String getAuthFailed() {
return authFailed;
}
public void setAuthFailed(String value) {
this.authFailed = value;
}
public String getSoapMessage() {
return soapMessage;
}
public void setSoapMessage(String value) {
this.soapMessage = value;
}
}
答案 0 :(得分:2)
我无法发表评论(不足以代表)澄清,但当你说你不能将country
添加为GetTestDetailResponse
的子元素时,我认为你会得到XML无效错误。
在WSDL中查看XML模式,没有定义country
元素
<xs:element name="GetTestDetailResponse" type="tns:GetTestDetailResponse"/>
所以将类型改为这样的东西应该有效:
<xs:complexType name="GetTestDetailResponse">
<xs:sequence>
<xs:element minOccurs="1" name="GetTestDetailResult" type="tns:GetTestDetailResult"/>
<xs:element minOccurs="0" name="country" type="xs:string"/>
<xs:element minOccurs="0" name="age" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
我还添加了年龄,因为这会有类似的问题。