这是我的整个WSDL:
<?xml version="1.0" encoding="utf-8"?> <definitions name="TokenService" targetNamespace="urn:mace:ideas:TokenNamespace" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:mace:ideas:TokenNamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <types> <xs:schema targetNamespace="urn:mace:ideas:TokenNamespace" version="1.0" xmlns:tns="urn:mace:ideas:TokenNamespace" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- A single HTTP header --> <xs:complexType name="httpHeader"> <xs:sequence> <xs:element name="Content" type="xs:string" /> <xs:element name="Usage"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="new" id="new" /> <xs:enumeration value="always" id="always" /> <xs:enumeration value="once" id="once" /> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType> <!-- A list of HTTP headers --> <xs:complexType name="httpHeaders"> <xs:sequence> <xs:element name="httpHeader" type="tns:httpHeader" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <!-- EACommand Id --> <xs:simpleType name="EACommandId"> <xs:restriction base="xs:string"> <xs:enumeration value="ReadDG" /> <xs:enumeration value="ReadRD" /> <xs:enumeration value="WriteRD" /> <xs:enumeration value="VerifyData" /> <xs:enumeration value="CheckAge" /> </xs:restriction> </xs:simpleType> <!-- EACommand operator --> <xs:simpleType name="EACommandOperator"> <xs:restriction base="xs:string"> <xs:enumeration value="equal" /> <xs:enumeration value="less" /> <xs:enumeration value="greater" /> </xs:restriction> </xs:simpleType> <!-- EACommand --> <xs:complexType name="EACommand"> <xs:sequence> <xs:element minOccurs="1" maxOccurs="1" name="EACommandId" type="tns:EACommandId" /> <xs:element minOccurs="0" maxOccurs="1" name="dataId" type="xs:integer" /> <xs:element minOccurs="0" maxOccurs="1" name="EACommandOperator" type="tns:EACommandOperator" /> <xs:element minOccurs="0" maxOccurs="1" name="value" type="xs:string" /> </xs:sequence> </xs:complexType> <!-- Batch command --> <xs:complexType name="batchCommand"> <xs:sequence> <xs:element name="stopOnAnyError" type="xs:boolean" nillable="false" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="command" type="tns:EACommand" /> </xs:sequence> </xs:complexType> <!-- TokenRequest --> <xs:complexType name="tokenRequest"> <xs:sequence> <xs:element minOccurs="1" name="raCode" type="xs:string" /> <xs:element minOccurs="1" name="appRefId" type="xs:string" /> <xs:element minOccurs="1" name="deptCode" type="xs:string" /> <xs:element minOccurs="1" name="raArtifactReceiverURL" type="xs:string" /> <xs:element minOccurs="1" name="target" type="xs:string" /> <xs:element minOccurs="0" name="dvnHash" type="xs:string" /> <xs:element minOccurs="0" name="msgHash" type="xs:string" /> <xs:element minOccurs="0" name="spinAction" type="xs:string" /> <xs:element minOccurs="0" name="locale" type="xs:string" /> <xs:element minOccurs="0" name="termsAndConditions" type="xs:string" /> <xs:element minOccurs="0" name="removeCard" type="xs:string" /> <xs:element minOccurs="0" name="reader" type="xs:string" /> </xs:sequence> </xs:complexType> <!-- GetToken,a wrapper for TokenRequest --> <xs:complexType name="getToken"> <xs:sequence> <xs:element minOccurs="1" name="tokenRequest" type="tns:tokenRequest" /> </xs:sequence> </xs:complexType> <!-- TokenResponse --> <xs:complexType name="tokenResponse"> <xs:sequence> <xs:element minOccurs="1" name="ideasArtifactReceiverURL" type="xs:string" /> <xs:element minOccurs="1" name="ideasMAURL" type="xs:string" /> <xs:element minOccurs="1" name="errorCode" type="xs:string" /> <xs:element minOccurs="1" name="errorMessage" type="xs:string" /> </xs:sequence> </xs:complexType> <!-- getTokenResponse,a wrapper for TokenResponse --> <xs:complexType name="getTokenResponse"> <xs:sequence> <xs:element minOccurs="1" name="return" type="tns:tokenResponse" /> </xs:sequence> </xs:complexType> <xs:element name="getToken" type="tns:getToken" /> <xs:element name="batchCommand" type="tns:batchCommand" /> <xs:element name="httpHeaders" type="tns:httpHeaders" /> <xs:element name="getTokenResponse" type="tns:getTokenResponse" /> </xs:schema> </types> <message name="TokenService_getToken"> <part element="tns:getToken" name="getToken" /> </message> <message name="TokenService_getToken2"> <part element="tns:getToken" name="getToken" /> <part element="tns:batchCommand" name="batchCommand" /> <part element="tns:httpHeaders" name="httpHeaders" /> </message> <message name="TokenService_getTokenResponse"> <part element="tns:getTokenResponse" name="getTokenResponse" /> </message> <portType name="TokenService"> <operation name="getToken" parameterOrder="getToken"> <input message="tns:TokenService_getToken" /> <output message="tns:TokenService_getTokenResponse" /> </operation> <operation name="getToken2" parameterOrder="getToken batchCommand httpHeaders"> <input message="tns:TokenService_getToken2" /> <output message="tns:TokenService_getTokenResponse" /> </operation> </portType> <binding name="TokenServiceBinding" type="tns:TokenService"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="getToken"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> <operation name="getToken2"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <service name="TokenService"> <port binding="tns:TokenServiceBinding" name="TokenServicePort"> <soap:address location="https://www0.ideas.hksarg/ideas/TokenService" /> </port> </service> </definitions>
当我生成一个存根(使用Eclipse Oxygen,自上而下,Axis1)时,该函数生成如下:
public TokenNamespace.ideas.mace.TokenResponse getToken(TokenNamespace.ideas.mace.TokenRequest tokenRequest) throws java.rmi.RemoteException { return null; } public TokenNamespace.ideas.mace.TokenResponse getToken2(TokenNamespace.ideas.mace.TokenRequest tokenRequest,boolean stopOnAnyError,TokenNamespace.ideas.mace.EACommand[] command,TokenNamespace.ideas.mace.HttpHeader[] httpHeader) throws java.rmi.RemoteException { return null; }
为什么TokenRequest类保持不变,而BatchCommand和HttpHeaders被拆除?
我尝试在HttpHeaders和BatchCommand下添加更多子元素,但它们只是作为附加参数拆分.我发现他们的声明和getToken之间没有任何区别.
解决方法
如果你在谈论getToken2()方法,那么实际上它们并没有被拆除,而是你看到httpheaders实际上是一个httpheader数组,所以在java代码中它被转换为一个httpheaders数组作为getToken2的参数,同样是CommandBatch的情况.
和
如果您正在讨论为什么从getToken()方法中拆除它们,那么解决方案如下所示.
这是因为在wsdl文件中没有为getToken()方法定义参数
例如,你有这个
<portType name="TokenService"> <operation name="getToken" parameterOrder="getToken"> <input message="tns:TokenService_getToken" /> <output message="tns:TokenService_getTokenResponse" /> </operation> <operation name="getToken2" parameterOrder="getToken batchCommand httpHeaders"> <input message="tns:TokenService_getToken2" /> <output message="tns:TokenService_getTokenResponse" /> </operation> </portType>
你应该像下面这样更新它
<portType name="TokenService"> <operation name="getToken" parameterOrder="getToken batchCommand httpHeaders"> <input message="tns:TokenService_getToken" /> <output message="tns:TokenService_getTokenResponse" /> </operation> <operation name="getToken2" parameterOrder="getToken batchCommand httpHeaders"> <input message="tns:TokenService_getToken2" /> <output message="tns:TokenService_getTokenResponse" /> </operation> </portType>
那就是你的操作getToken应该在parameterOrder属性中定义所需的参数.
并且还要更改消息
<message name="TokenService_getToken"> <part element="tns:httpHeaders" name="httpHeaders" /> </message>
至
<message name="TokenService_getToken"> <part element="tns:getToken" name="getToken" /> <part element="tns:batchCommand" name="batchCommand" /> <part element="tns:httpHeaders" name="httpHeaders" /> </message>
你可以进一步看看这个answer它解释了如何使用maxOccurs属性.如果未指定,则元素将仅出现一次.这就是为什么getToken没有像其他参数一样被更改为数组,而是被TokenRequest的一次出现所取代,而TokenRequest实际上是getToken complexType中包含的内容.这是TokenRequest的一次出现