0
我想通過一個Ruby腳本從PHP頁面調用Web服務。 PHP腳本返回一個字符串,並自己調用另一個Web服務;我已經測試了PHP腳本,並且它返回一個單獨的字符串。我試着用下面的代碼來調用通過RPC這個方法:Ruby REXML拋出ParseException,但PHP的XML解析器工作
require 'soap/rpc/driver'
driver = SOAP::RPC:Driver.new('http://mysite.com/services/webservices.php', 'urn:mysite')
driver.add_method('getMobileCarrier', 'phoneNumber')
driver.getMobileCarrier('15551234567') # fake number, obviously
我得到這樣的結果回:
REXML::ParseException: malformed XML: missing tag start
Line:
Position:
Last 80 unconsumed characters:
< in <b>/var/www/html/services/webservices.php</b>
from /opt/local/lib/ruby/1.8/rexml/parsers/baseparser.rb:356:in `pull'
from /opt/local/lib/ruby/1.8/rexml/parsers/streamparser.rb:16:in `parse'
from /opt/local/lib/ruby/1.8/rexml/document.rb:201:in `parse_stream'
from /opt/local/lib/ruby/1.8/xsd/xmlparser/rexmlparser.rb:27:in `do_parse'
from /opt/local/lib/ruby/1.8/soap/parser.rb:92:in `parse'
from /opt/local/lib/ruby/1.8/soap/processor.rb:39:in `unmarshal'
from /opt/local/lib/ruby/1.8/soap/rpc/proxy.rb:236:in `unmarshal'
from /opt/local/lib/ruby/1.8/soap/rpc/proxy.rb:175:in `route'
from /opt/local/lib/ruby/1.8/soap/rpc/proxy.rb:141:in `call'
from /opt/local/lib/ruby/1.8/soap/rpc/driver.rb:178:in `call'
from /opt/local/lib/ruby/1.8/soap/rpc/driver.rb:232:in `getMobileCarrier'
from (irb):4
當我運行PHP代碼本身但是(並給它一個真正的價值,顯然)它不會拋出任何錯誤並返回預期值。它只是不適用於Ruby和REXML;我怎樣才能解決這個問題? PHP腳本調用的Web服務是由第三方調用的,我無法修改響應,但顯然響應在PHP中正常工作,但REXML遇到問題。
奇怪的是,PHP腳本沒有返回XML,而是從它所調用的Web服務中解析XML,並簡單地返回一個字符串值。 – 2009-12-10 22:46:24
如果您想要soap lib解析它,則返回的字符串值必須是有效的soap響應。如果你的webservices.php沒有像一個合適的soap監聽器那樣工作,那麼你可以更好地服務於修復php腳本或者編寫一個與php腳本行爲相對應的ruby簡單客戶端。 – 2009-12-10 22:57:20
ruby簡單客戶端=簡單的ruby客戶端 – 2009-12-10 22:57:58