views:

249

answers:

1

I'm trying to call a web service from a PHP page via a Ruby script. The PHP script returns a string and itself calls another web service; I've tested the PHP script alone and it returns a single string. I'm trying to call this method via RPC using the following code:

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

I get this result back:

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

However when I run the PHP code itself (and give it a real value, obviously) it doesn't throw any errors at all and returns the expected value. It's just not working with Ruby and REXML; how can I fix this? The web service that the PHP script is calling is by a third-party and I cannot modify the response, but obviously the response is working fine in PHP but REXML has an issue with it.

+1  A: 

Without the xml that is returned it's hard to say. Have you tried using an xml validation tool like: xmlstarlet, xmllint, or tidy.

These tools will tell you if your xml is well formed. If it's not well formed then it depends on what's wrong with it as to how you can fix it.

Post more details for a better answer.

Mark Carey
The weird thing is the PHP script isn't returning XML, it's parsing XML from the web service that *it* calls and simply returning a string value.
Wayne M
The string value returned needs to be a valid soap response if you want the soap lib to parse it. If your webservices.php is not behaving as a proper soap listener then you would be better served fixing the php script or writing a ruby simple client that corresponds to the behavior of the php script.
Mark Carey
ruby simple client = simple ruby client
Mark Carey