cwang82566
作者 cwang82566 · 2013-03-08 14:22
软件开发工程师·IBM

如何用Web Serivces Wrapper返回多条记录?

字数 6856 阅读 2318 评论 0 赞 0

还以上篇文章为例子,返回省市的电视台编码,省市名和所属地区

http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx

getAreaDataSet

 获得支持的省市(地区)和分类电视列表 DataSet

输入参数:无;返回数据:DataSet,结构为:Item(areaID)=省市和分类电视ID,Ietm(Area)=省市和分类电视名称,Item(Zone)=所属地区。

如果不用子昵称去解析结果集,Web Serivce wrapper并不会递归查找解析,它会返回全部或者只返回第一个子

drop nickname getAreaDataSetByOneRow ;
CREATE NICKNAME getAreaDataSetByOneRow
(
Areas varchar(200) OPTIONS(XPATH './ns1:getAreaDataSetResponse/ns1:getAreaDataSetResult/ns2:diffgram/Area')
)
FOR SERVER MYWSSERVER
OPTIONS(URL 'http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx' , SOAPACTION 'http://WebXml.com.cn/getAreaDataSet' , TEMPLATE '<soapenv:Envelope><soapenv:Body></soapenv:Body></soapenv:Envelope>' , XPATH '/soapenv:Envelope/soapenv:Body' , NAMESPACES ' ns1="http://WebXml.com.cn/",ns2="urn:schemas-microsoft-com:xml-diffgram-v1", soapenv="http://schemas.xmlsoap.org/soap/envelope/" ');
select * from getAreaDataSetByOneRow ;

db2 => select * from getAreaDataSetByOneRow ;

AREAS

--------------------------------------------------------------------------------
-4数字电视数字-3海外电视海外-2卫星电视卫星-1中央电视中央1北京市华北地区2天津市华
北地区3河北省华北地区4山西省华北地区5内蒙古自治区华北地区6辽宁省东北地区7吉林省
东北地区8黑龙江省东北地区9上海市华东地区10江苏省华东地区11浙江省华东地区12安徽省
华中地区13福建省华南地区14江西省华中地区15山东省华东地区16河南省华中地区17湖北省
华中地区18湖南省华中地区19广东省华南地区20广西壮族自治区华南地区21海南省华南地区
22重庆市西南地区23四川省西南地区24贵州省西南地区25云南省西南地区26西藏自治区西南
地区27陕西省西北地区28甘肃省西北地区29青海省西北地区30宁夏回族自治区西北地区31新
疆维吾尔自治区西北地区32香港港澳台地区33澳门港澳台地区34台湾省港澳台地区

  1 条记录已选择。

而如何返回多行记录,必须根据返回结果集的schema 定义来建立子昵称,Inforamtion Center 有介绍,link如下:

http://pic.dhe.ibm.com/infocenter/db2luw/v10r1/index.jsp?topic=%2Fcom.ibm.swg.im.iis.found.conn.fw.wss.doc%2Ftopics%2Frlswss04.html

这里通过简单例子来教你如何熟练掌握窍门,如何创建昵称请参阅“联邦数据库(InfoSphere Federation Server)使用Web Service2012”

返回值的Soap envelope:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getAreaDataSetResponse xmlns="http://WebXml.com.cn/">
      <getAreaDataSetResult>
        <xsd:schema>schema</xsd:schema>xml</getAreaDataSetResult>
    </getAreaDataSetResponse>
  </soap:Body>
</soap:Envelope>

返回值的schemal和xml

<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://WebXml.com.cn/">
  <xs:schema id="Area" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="Area" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="AreaList">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="areaID" type="xs:int" minOccurs="0" />
                <xs:element name="Area" type="xs:string" minOccurs="0" />
                <xs:element name="Zone" type="xs:string" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
    <Area xmlns="">
      <AreaList diffgr:id="AreaList1" msdata:rowOrder="0">
        <areaID>-4</areaID>
        <Area>数字电视</Area>
        <Zone>数字</Zone>
      </AreaList>
  ......
      <AreaList diffgr:id="AreaList38" msdata:rowOrder="37">
        <areaID>34</areaID>
        <Area>台湾省</Area>
        <Zone>港澳台地区</Zone>
      </AreaList>
    </Area>
  </diffgr:diffgram>
</DataSet>

CREATE NICKNAME getAreaDataSet
(
NN_PKEY VARCHAR (16) NOT NULL OPTIONS(PRIMARY_KEY 'YES')
)
FOR SERVER MYWSSERVER
OPTIONS(URL 'http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx' , SOAPACTION 'http://WebXml.com.cn/getAreaDataSet' , TEMPLATE '<soapenv:Envelope><soapenv:Body></soapenv:Body></soapenv:Envelope>' , XPATH '/soapenv:Envelope/soapenv:Body' , NAMESPACES ' ns1="http://WebXml.com.cn/",ns2="urn:schemas-microsoft-com:xml-diffgram-v1", soapenv="http://schemas.xmlsoap.org/soap/envelope/" ');


CREATE NICKNAME getAreaDataSet_getarealist_nn (
NN_FKEY VARCHAR (16) NOT NULL OPTIONS(FOREIGN_KEY 'GETAREADATASET'),
areaid int OPTIONS(XPATH './areaID/text()'),
Area varchar(50) OPTIONS(XPATH './Area/text()'),
Zone varchar(50) OPTIONS(XPATH './Zone/text()')
)
FOR SERVER MYWSSERVER OPTIONS(
XPATH './ns1:getAreaDataSetResponse/ns1:getAreaDataSetResult/ns2:diffgram/Area/AreaList' ,
NAMESPACES ' soapenv="http://schemas.xmlsoap.org/soap/envelope/" ,
ns1="http://WebXml.com.cn/",ns2="urn:schemas-microsoft-com:xml-diffgram-v1" ');

db2 => SELECT areaid,Area, Zone FROM getAreaDataSet,
getAreaDataSet_getarealist_nn
WHERE NN_PKEY=NN_FKEY;

AREAID AREA ZONE

----------- -------------------------------------------------- --------------
---------------------------------
-4 数字电视 数字

-3 海外电视 海外

-2 卫星电视 卫星

-1 中央电视 中央

1 北京市 华北地区

2 天津市 华北地区

......
  38 条记录已选择。

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广