R – Consuming a SOAP Rails Webservice doesn’t work in Delphi 2009 but was Ok in Delphi 2006

delphidelphi-2009ruby-on-railssoapweb services

I have a soap webservice written in RubyOnRails and a client written in Delphi. The client and server comunicate fine using Delphi 2006, but compiling with the newer Delphi 2009 causes the Rails server to "crash".

This is the request (generated by built in THTTPRIO):

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><NS1:IsValidCouponCode xmlns:NS1="urn:ActionWebService"><coupon_code xsi:type="xsd:string">1VK3K-7N45K-4V76W-JCS2F-NC125</coupon_code></NS1:IsValidCouponCode></SOAP-ENV:Body></SOAP-ENV:Envelope>

This is the "response" of the Rails webservice

Internal protocol error: Bad encoding name "UTF-8"
Backtrace:
/usr/lib/ruby/1.8/rexml/encoding.rb:31:in `encoding='
/usr/lib/ruby/1.8/rexml/source.rb:54:in `encoding='
/usr/lib/ruby/1.8/xsd/xmlparser/rexmlparser.rb:24:in `do_parse'
/usr/lib/ruby/1.8/soap/parser.rb:92:in `parse'
/usr/lib/ruby/1.8/soap/processor.rb:39:in `unmarshal'
[...]

So it seems clear that something with "UTF-8" encoding is different in Delphi 2009, but I have no idea how to change this.

Best Answer

I found a solution. After comparing the requests which were basically the same (Delphi 2006 only had some more linebreaks and indentions in the xml) I found the difference in the HTTP-Header (using Wireshark)

Delphi 2006: Content-Type: text/xml
Delphi 2009: Content-Type: text/xml; charset="utf-8"

The Solution:

RIO.HTTPWebNode.UseUTF8InHeader := False; 

The default value for this property had changed from Delphi 2006 to Delphi 2009

Conclusion: It seems to be a bug in Ruby (on Rails). It worked with both Delphi-Versions with a local installation of the webservice on a Windows machine. Only the production machine running Linux had the problem.

Related Topic