Web 服务调用 Return

Web Service Call Return

我正在测试不同 Web 服务调用的性能,想知道如何指定在响应中返回哪些字段。我在想,如果我只查询某些字段,将返回较少的信息,因此响应时间会更快。我怎样才能以这种格式完成它?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 

xmlns:ns="http://schemas.hp.com/SM/7" xmlns:com="http://schemas.hp.com/SM/7/Common" xmlns:xm="http://www.w3.org/2005/05/xmlmime">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:RetrieveChangeTaskListRequest>
         <ns:model>

        <ns:keys query="AssignedTo = &quot;drake&quot; and planned.start &gt; '03/01/2016' and planned.start &lt; tod()" ></ns:keys>
        <ns:instance></ns:instance>

     </ns:model>
  </ns:RetrieveChangeTaskListRequest>
</soapenv:Body>
</soapenv:Envelope>

你不能用 SOAP 做你想做的事情,因为它 returns 完整 objects 所有字段都完好无损。

但是如果你想缩小负载大小,你可以尝试启用 gzip 压缩,如果网络服务器支持它,你会得到一个很好的微小响应。像这样实例化 soapclient:

$soapclient = new SoapClient($uri, array(
  'soap_version'  => SOAP_1_1,
  'trace' => 1,
  'exceptions' => true,
  'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP
  )
);

然后您可以检查 header 以查看响应是否被压缩,方法是对请求执行 $soapclient->__getLastRequestHeaders(),对响应执行 $soapclient->__getLastResponseHeaders()

在请求 header 中,您应该看到:Accept-Encoding: gzip, deflate 和响应 header:Content-Encoding: gzip 以及 Transfer-Encoding: chunked,您知道它有效。