在我们Web服务的性能测试中,我们发现响应生成的流量超出了我们的预期。我们正在查询包含行和列的数据库和加载列表。优化Web服务的XML响应
该列的类型是AnyType所以在响应中需要一个类型信息。因此,Web服务引擎(Axis2或JAXWS)多次添加命名空间信息。请看下面的例子响应:
<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>
我想优化由在顶部加入所需的命名空间和从每一列中除去他们这个XML响应(一般有每行约30列)。结果应该是这样的:
<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?
是的,我们正在考虑这一点。在服务器端有一个Apache,所以mod_deflate应该做的工作......但.NET客户端需要能够处理压缩的响应。 – 2009-12-21 10:25:47