如何在SOAP UI中传递参数

时间:2012-07-27 15:34:19

标签: xml soap soapui

我正在尝试使用SOAPUI的SOAP api。 WSDL中描述的“get”操作如下所示:

 <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:MarketingCenter" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
       <soapenv:Header/>
       <soapenv:Body>
          <urn:Get soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
             <Authentication xsi:type="urn:Authentication">
                <!--You may enter the following 6 items in any order-->
                <Username xsi:type="xsd:string">myUserName</Username>
                <Password xsi:type="xsd:string">mypassword</Password>
                <CustomerId xsi:type="xsd:int">29833</CustomerId>
                <Level xsi:type="xsd:int">0</Level>
                <Source xsi:type="xsd:string">?</Source>
                <Options xsi:type="xsd:int">0</Options>
             </Authentication>
             <Method xsi:type="xsd:string">keyword.list</Method>
             <Arguments xsi:type="urn:ArrayOfKeyValuePairs" soapenc:arrayType="urn:KeyValuePair[]"/>
          </urn:Get>
       </soapenv:Body>
    </soapenv:Envelope>

但是当我运行此操作时,我收到以下错误:

    <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns4="urn:MarketingCenter">
   <SOAP-ENV:Body>
      <ns4:GetResponse>
         <return xsi:type="ns4:GetResponseData">
            <Data xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[0]" xsi:nil="true"/>
            <Status>
               <ErrorCode xsi:type="xsd:int">1</ErrorCode>
               <ErrorString xsi:type="xsd:string">One or more of the arguments were invalid</ErrorString>
               <ErrorDetails xsi:type="xsd:string">One or more of the arguments were invalid</ErrorDetails>
            </Status>
         </return>
      </ns4:GetResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我不知道我应该在哪里,但参数列表,或如何格式化此列表。我确实意识到他们想要一个参数数组,但是我应该把这个数组放在哪里?无论我在哪里放入其他值都有一个'?',所以我不知道在哪里输入这个argumentw数组。

1 个答案:

答案 0 :(得分:2)

期待你在这里投入实际价值:

<Authentication xsi:type="urn:Authentication">
    <!--You may enter the following 6 items in any order-->
    <Username xsi:type="xsd:string">myUserName</Username>
    <Password xsi:type="xsd:string">mypassword</Password>
    <CustomerId xsi:type="xsd:int">29833</CustomerId>
    <Level xsi:type="xsd:int">0</Level>
    <Source xsi:type="xsd:string">?</Source>
    <Options xsi:type="xsd:int">0</Options>
</Authentication>

参数列表只是UsernamePasswordCustomerId等。而不是myUserNamemypassword放入服务所期望的任何内容。

至于:

<Arguments xsi:type="urn:ArrayOfKeyValuePairs" soapenc:arrayType="urn:KeyValuePair[]"/>

这可能看起来像:

<urn:Get>
    ...
    <Arguments xsi:type="urn:ArrayOfKeyValuePairs" soapenc:arrayType="urn:KeyValuePair[5]">
        <KeyValuePair>
            <Key xsi:type="xsd:string">foo</Key>
            <Value xsi:type="xsd:string">bar</Value>
        </KeyValuePair>
        <KeyValuePair>...</KeyValuePair>
        <KeyValuePair>...</KeyValuePair>
        <KeyValuePair>...</KeyValuePair>
        <KeyValuePair>...</KeyValuePair>
    </Arguments>
</urn:Get>

其中的内容取决于服务如何定义该类型(根据WSDL只是<Key>元素和<Value>元素)。确保方括号([5])中的数字与<KeyValuePair>元素的数量匹配。