如何从服务器检索特定的Web服务响应

时间:2018-11-30 19:49:36

标签: java .net soap soapui soap-client

Web服务提供商已向我们(客户端)提供了wsdl以使用其服务并使用数据。我们的要求是,我们只需要特定的节点值“ CHASE”,请参见下面的测试数据。我们不想在响应中获取所有信息记录和相应的节点。

这是我们在SOAPUI工具中测试过的示例。请提出建议并帮助我们,如何从提供的URL(http://host:port/ValueMappingInService/ValueMappingInImplBean)的角度来构架Web服务请求?是否有可能向下钻取请求并从客户端获得特定响应?

Web服务请求:-

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:bas="http://sap.com/xi/BASIS">
  <soapenv:Header/>
   <soapenv:Body>
      <bas:ValueMappingReadRequest>
         <!--Optional:-->
         <ReadContext>User</ReadContext>
    <!--Zero or more repetitions:-->
     <ValueMappingID>c44f541f-c8ac-11e8-86e5-0050569d98cc</ValueMappingID>
  </bas:ValueMappingReadRequest>
  </soapenv:Body>
</soapenv:Envelope>

 Web service Response:-

<SOAP-ENV:Envelope xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SOAP- 
 ENV="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <SOAP-ENV:Body>
      <ns2:ValueMappingReadResponse xmlns:ns2="http://sap.com/xi/BASIS">
         <ValueMapping>
           <MasterLanguage>EN</MasterLanguage>
            <AdministrativeData>
           <ResponsibleUserAccountID>gdonna</ResponsibleUserAccountID>
           <LastChangeUserAccountID>gdonna</LastChangeUserAccountID>
           <LastChangeDateTime>2018-10-05T09:47:38.237-05:00</LastChangeDateTime>
           <FolderPathID>/</FolderPathID>
        </AdministrativeData>
        <ValueMappingID>c44f541f-c8ac-11e8-86e5-0050569d98cc</ValueMappingID>
        <GroupName>Mercedes</GroupName>
        <Representation schemeAgencyID="LOC_BANK" schemeID="BANK">CHASE</Representation>
        <Representation schemeAgencyID="LOC_SITE" schemeID="DIR">comm/as2/chase/receive/</Representation>
        <Representation schemeAgencyID="LOC_COUNTRY" schemeID="CODE">US</Representation>
     </ValueMapping>
     <LogMessageCollection/>
  </ns2:ValueMappingReadResponse>
    </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

1 个答案:

答案 0 :(得分:0)

尝试使用Groovy脚本。我真的很喜欢XMLSlurper的功能,当它们更改时,我可以忽略它们。

只需添加一个新的Groovy脚本测试步骤,并将其放入其中即可。您只需要调整您的Soap Request测试步骤的名称,该名称应放在此测试步骤的前面。

/** The name should be modified to match the request/response you want to validate */
def holder =  new com.eviware.soapui.support.GroovyUtils( context ).getXmlHolder("The Name Of Your Soap Request TestStep#Response")
def response = new XmlSlurper().parseText(holder.getXml())
for (def element : response.Body.ValueMappingReadResponse.ValueMapping.Representation) 
{
   log.info element
   log.info element.@'schemeAgencyID'
}