1、环境配置:
1)先安装ruby后,在命令提示窗口执行下面命令安装soap
gem update --system
gem install soap4r
2、示例:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1 require 'soap/wsdlDriver'
2 require "rexml/document"
3
4 wsdl = "http://h-invitational.jp/hinv/hws/soap_acc2hit.php?wsdl"
5
6 serv = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
7
8 #调用服务方法
9 result = serv.acc2hit("BC053657")
10
11 xml = REXML::Document.new(result)
12
13 #服务返回的结果如下:
14 # <?xml version='1.0' encoding='UTF-8'?>
15 # <H-Inv>
16 # <H-INVITATIONAL-ID>HIT000053961</H-INVITATIONAL-ID>
17 # </H-Inv>
18
19 #打印出获取xml的版本号
20 p xml.version()
21
22 #解析xml
23 xml.elements.each("H-Inv/H-INVITATIONAL-ID") do |element|
24 puts element.text
25 end
运行结果如下:
"1.0"
HIT000053961