首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >优化web服务的XML响应

优化web服务的XML响应
EN

Stack Overflow用户
提问于 2009-12-21 09:53:51
回答 3查看 2K关注 0票数 1

在我们的web服务的性能测试中,我们发现响应产生的流量远远超出了我们的期望。我们正在查询数据库并加载由行和列组成的列表。

列的类型是AnyType,因此响应中需要有类型信息。为此,web服务引擎(Axis2或JAXWS)多次添加大量命名空间信息。请参见以下示例响应:

代码语言:javascript
运行
复制
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns3:loadListResponse xmlns:ns3="http://example.com/test/service-types-1.0" 
      xmlns:ns2="http://example.com/lists/lists-types-1.0" >
         <ns3:value>
            <ns2:row>
               <ns2:column xsi:type="xs:int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">12345</ns2:column>
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">XYZ</ns2:column>
               <ns2:column xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">ABC</ns2:column>
            </ns2:row>
            <ns2:row>
               <ns2:column xsi:type="xs:int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">32345</ns2:column>
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">OPC</ns2:column>
               <ns2:column xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">QWE</ns2:column>
            </ns2:row>
             .
             .
             .
         </ns3:value>
      </ns3:loadListResponse>
   </soapenv:Body>
</soapenv:Envelope>

我希望通过在顶部添加所需的名称空间并从每一列中删除它们(通常每一行大约有30列)来优化这个XML响应。结果应该如下所示:

代码语言:javascript
运行
复制
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <soapenv:Body>
      <ns3:loadListResponse xmlns:ns3="http://example.com/test/service-types-1.0" 
      xmlns:ns2="http://example.com/lists/lists-types-1.0" >
         <ns3:value>
            <ns2:row>
               <ns2:column xsi:type="xs:int" >12345</ns2:column>
               <ns2:column xsi:type="xs:string" >XYZ</ns2:column>
               <ns2:column xsi:nil="true" />
               <ns2:column xsi:type="xs:string" >ABC</ns2:column>
            </ns2:row>
            <ns2:row>
               <ns2:column xsi:type="xs:int" >32345</ns2:column>
               <ns2:column xsi:type="xs:string" >OPC</ns2:column>
               <ns2:column xsi:nil="true" />
               <ns2:column xsi:type="xs:string" >QWE</ns2:column>
            </ns2:row>
             .
             .
             .
         </ns3:value>
      </ns3:loadListResponse>
   </soapenv:Body>
</soapenv:Envelope>

你会怎么做那样的事?

有没有办法告诉Axis2或JAXWS这样做?

还是需要手动操作生成的XML?

EN

Stack Overflow用户

回答已采纳

发布于 2009-12-21 09:57:42

您是否考虑过尝试以适当透明的方式压缩响应?这可能更容易做,并将非常有效的所有这些重复的数据。

票数 3
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1939200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档