利用webservice获得xml信息可能出现一些影响

场景:服务端使用java开发,发布web服务,客户端使用delphi开发展示数据,两者通过webservice来通讯。

在测试中,客户端请求一个xml文档(该文档存放于oracle数据库中,CLOB型),发现有时候能正常取到,有时候取到的数据以xml方式解析解析不了。

而我使用java客户端来请求该数据时,又能正常得到所有xml数据,和库中一样。为了彻底解决这个问题,写了一个测试的webservice接口。

java 代码
  1. public class TestService {   
  2.     public TestService() {   
  3.     }   
  4.   
  5.     public String getMessage() {   
  6.             return message;   
  7.     }   
  8. }  

这里的message其实是一个xml文档(由于不能贴在里,会丢信息原来信息无法阅读,所以在后面贴出)。

若message赋值为xml_a时,delphi客户端没有任何问题,能得到正常结果。xml_a内容如下:

xml 代码
  1. String xml_a =   
  2.     "<<!---->xml version=\"1.0\" encoding=\"UTF-8\"?>"
  3.         + " <bCCH_BCH_Message>xxyyzz"   
  4.         + " <message>"   
  5.         + "   <sfn_Prime>25sfn_Prime>"   
  6.         + "   <payload>"   
  7.         + "      <completeSIB_List>"   
  8.         + "         <element>"   
  9.         + "            <sib_Type>systemInformationBlockType7sib_Type>"   
  10.         + "            <sib_Data_variable>01 80 80sib_Data_variable>"   
  11.         + "         element>"   
  12.         + "         <element>"   
  13.         + "            <sib_Type>schedulingBlock1sib_Type>"   
  14.         + "            <sib_Data_fixed>08 0D B0 1D 05 80 C4 4C 06 A0sib_Data_fixed>"  
  15.         + "         element>"   
  16.         + "      completeSIB_List>"   
  17.         + "   payload>"   
  18.         + " message>"   
  19.         + " <xxyyzz1>xxyyzz123xxyyzz1>"   
  20.         + " <xxyyzz1>xxyyzz987xxyyzz1>"   
  21.         + " bCCH_BCH_Message>";   

用tcptrace工具得到的返回结果,<写为<,>为>,&为&,这是由于是传输的数据就是以XML,在这个xml文档内再包含其他xml内容时需要转义。

当xml_b(比较长)赋值给message时,如下:

xml 代码
  1. String xml_b =    
  2. "<!---->xml version=\"1.0\" encoding=\"UTF-8\"?>"   
  3.     + "<uL_DCCH_Message>                        "   
  4.     + "<xyz>"    
  5.     +"  <a>1a>"    
  6.     +"  <b>2b>"    
  7.     +"  <c>3c>"    
  8.     +"  <d>4d>"    
  9.     +"  <e>5e>"    
  10.     +"  <f>6f>"    
  11.     +"  <g>7g>"    
  12.     +"  <h>8h>"    
  13.     +"  <i>9i>"    
  14.     +"  <j>10j>"    
  15.     +"  <k>11k>"    
  16.     +"  <l>12l>"    
  17.     +"  <m>13m>"    
  18.     +"xyz>"   
  19.     + "   <message>"   
  20.     + "      <rrcConnectionSetupComplete>"   
  21.     + "         <rrc_TransactionIdentifier>0rrc_TransactionIdentifier>"   
  22.     + "         <startList>"   
  23.     + "            <element>"   
  24.     + "               <cn_DomainIdentity>cs_domaincn_DomainIdentity>"   
  25.     + "               <start_Value>00000000000000000100start_Value>"   
  26.     + "            element>"   
  27.     + "            <element>"   
  28.     + "               <cn_DomainIdentity>ps_domaincn_DomainIdentity>"   
  29.     + "               <start_Value>00000000000000010010start_Value>"   
  30.     + "            element>"   
  31.     + "         startList>"   
  32.     + "         <ue_RadioAccessCapability>"   
  33.     + "            <accessStratumReleaseIndicator>r99accessStratumReleaseIndicator>"   
  34.     + "            <pdcp_Capability>"   
  35.     + "               <losslessSRNS_RelocationSupport>falselosslessSRNS_RelocationSupport>"   
  36.     + "               <supportForRfc2507>"   
  37.     + "                  <notSupported/>"   
  38.     + "               supportForRfc2507>"   
  39.     + "            pdcp_Capability>"   
  40.     + "            <rlc_Capability>"   
  41.     + "               <totalRLC_AM_BufferSize>kb150totalRLC_AM_BufferSize>"   
  42.     + "               <maximumRLC_WindowSize>mws2047maximumRLC_WindowSize>"   
  43.     + "               <maximumAM_EntityNumber>am6maximumAM_EntityNumber>"   
  44.     + "            rlc_Capability>"   
  45.     + "            <transportChannelCapability>"   
  46.     + "               <dl_TransChCapability>"   
  47.     + "                  <maxNoBitsReceived>b6400maxNoBitsReceived>"   
  48.     + "                  <maxConvCodeBitsReceived>b6400maxConvCodeBitsReceived>"   
  49.     + "                  <turboDecodingSupport>"   
  50.     + "                     <supported>b6400supported>"   
  51.     + "                  turboDecodingSupport>"   
  52.     + "                  <maxSimultaneousTransChs>e8maxSimultaneousTransChs>"   
  53.     + "                  <maxSimultaneousCCTrCH_Count>1maxSimultaneousCCTrCH_Count>"   
  54.     + "                  <maxReceivedTransportBlocks>tb32maxReceivedTransportBlocks>"   
  55.     + "                  <maxNumberOfTFC>tfc128maxNumberOfTFC>"   
  56.     + "                  <maxNumberOfTF>tf64maxNumberOfTF>"   
  57.     + "               dl_TransChCapability>"   
  58.     + "               <ul_TransChCapability>"   
  59.     + "                  <maxNoBitsTransmitted>b6400maxNoBitsTransmitted>"   
  60.     + "                  <maxConvCodeBitsTransmitted>b6400maxConvCodeBitsTransmitted>"   
  61.     + "                  <turboEncodingSupport>"   
  62.     + "                     <supported>b6400supported>"   
  63.     + "                  turboEncodingSupport>"   
  64.     + "                  <maxSimultaneousTransChs>e8maxSimultaneousTransChs>"   
  65.     + "                  <modeSpecificInfo>"   
  66.     + "                     <fdd/>"   
  67.     + "                  modeSpecificInfo>"   
  68.     + "                  <maxTransmittedBlocks>tb32maxTransmittedBlocks>"   
  69.     + "                  <maxNumberOfTFC>tfc64maxNumberOfTFC>"   
  70.     + "                  <maxNumberOfTF>tf64maxNumberOfTF>"   
  71.     + "               ul_TransChCapability>"   
  72.     + "            transportChannelCapability>"   
  73.     + "            <rf_Capability>"   
  74.     + "               <fddRF_Capability>"   
  75.     + "                  <ue_PowerClass>3ue_PowerClass>"   
  76.     + "                  <txRxFrequencySeparation>mhz190txRxFrequencySeparation>"   
  77.     + "               fddRF_Capability>"   
  78.     + "            rf_Capability>"   
  79.     + "            <physicalChannelCapability>"   
  80.     + "               <fddPhysChCapability>"   
  81.     + "                  <downlinkPhysChCapability>"   
  82.     + "                     <maxNoDPCH_PDSCH_Codes>1maxNoDPCH_PDSCH_Codes>"   
  83.     + "                     <maxNoPhysChBitsReceived>b9600maxNoPhysChBitsReceived>"   
  84.     + "                     <supportForSF_512>falsesupportForSF_512>"   
  85.     + "                     <supportOfPDSCH>falsesupportOfPDSCH>"   
  86.     + "                     <simultaneousSCCPCH_DPCH_Reception>"   
  87.     + "                        <notSupported/>"   
  88.     + "                     simultaneousSCCPCH_DPCH_Reception>"   
  89.     + "                  downlinkPhysChCapability>"   
  90.     + "                  <uplinkPhysChCapability>"   
  91.     + "                     <maxNoDPDCH_BitsTransmitted>b9600maxNoDPDCH_BitsTransmitted>"   
  92.     + "                     <supportOfPCPCH>falsesupportOfPCPCH>"   
  93.     + "                  uplinkPhysChCapability>"   
  94.     + "               fddPhysChCapability>"   
  95.     + "            physicalChannelCapability>"   
  96.     + "            <ue_MultiModeRAT_Capability>"   
  97.     + "               <multiRAT_CapabilityList>"   
  98.     + "                  <supportOfGSM>falsesupportOfGSM>"   
  99.     + "                  <supportOfMulticarrier>falsesupportOfMulticarrier>"   
  100.     + "               multiRAT_CapabilityList>"   
  101.     + "               <multiModeCapability>fddmultiModeCapability>"   
  102.     + "            ue_MultiModeRAT_Capability>"   
  103.     + "            <securityCapability>"   
  104.     + "               <cipheringAlgorithmCap>uea1 uea0cipheringAlgorithmCap>"   
  105.     + "               <integrityProtectionAlgorithmCap>uia1integrityProtectionAlgorithmCap>"   
  106.     + "            securityCapability>"   
  107.     + "            <ue_positioning_Capability>"   
  108.     + "               <standaloneLocMethodsSupported>falsestandaloneLocMethodsSupported>"   
  109.     + "               <ue_BasedOTDOA_Supported>falseue_BasedOTDOA_Supported>"   
  110.     + "               <networkAssistedGPS_Supported>noNetworkAssistedGPSnetworkAssistedGPS_Supported>"   
  111.     + "               <supportForUE_GPS_TimingOfCellFrames>falsesupportForUE_GPS_TimingOfCellFrames>"   
  112.     + "               <supportForIPDL>falsesupportForIPDL>"   
  113.     + "            ue_positioning_Capability>"   
  114.     + "            <measurementCapability>"   
  115.     + "               <downlinkCompressedMode>"   
  116.     + "                  <fdd_Measurements>truefdd_Measurements>"   
  117.     + "               downlinkCompressedMode>"   
  118.     + "               <uplinkCompressedMode>"   
  119.     + "                  <fdd_Measurements>truefdd_Measurements>"   
  120.     + "               uplinkCompressedMode>"   
  121.     + "            measurementCapability>"   
  122.     + "         ue_RadioAccessCapability>"   
  123.     + "      rrcConnectionSetupComplete>"   
  124.     + "   message>"   
  125.     + "uL_DCCH_Message>";   

每次delphi客户端得到的结果解析不了。后用tcptrace工具截获请求和webservice返回的结果,得出结果是:实际的xml文档被夹在CDATAT标记中间,并没有(<写为<,>为>,&为&)转义。这也是delphi获得的结果,delphi对获得的串类型没有作任何处理,所以无法解析,除非去掉首尾CDATAT部分。而java的客户端可以得到的结果(去掉了CDATAT标记),即不包含CDATAT部分。问题出现在各自的SOAP引擎(根据SOAP规范生成请求应答)或消息的解析上(解析以xml传过来的数据)。

 查了一下XML资料查到类似的一段:

若果XML文档中包含XML或HTML时,那么<和>和&分别写成<和>和&来转义;若包含的XML文档过长,把整个XML或HTML包在CDATA标记里,避免转义造成XML文档膨胀过大,尤其通过网络来传输的xml尤为重要。

再对照前面给出的2各XML文档,区别就是长度。若过长websphere就使用CDATA标记,若不太长则使用转义。到底多长才使用CDATA标记,没找到相关的说明。

但delphi却没有这么灵活,无法处理这种情况。我同事只好每次得到XML信息,先判断是否有CDATA标记,有就去头截尾。

你可能感兴趣的:(oracle,xml,webservice,SOAP,Delphi)