views:

104

answers:

2

I'm having problems receiving invalid non-ascii characters coming from a Delphi 7 client sending a utf-8 encoded XML to a C# WebService in a String parameter. With a .Net client, the characters are received without a problem. I've tried a lot of stuff, and nothing seemed to work, so I decided to trace the SOAP conversation with Wireshark. With the .Net client, the XML for the SOAP envelope is utf-8 encoded, as follows:

POST //TesteService/ServicoAgente.asmx HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.3615)
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://example.com/ValidarTransacao"
Host: 192.168.254.2
Content-Length: 1530
Expect: 100-continue
Connection: Keep-Alive

HTTP/1.1 100 Continue

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;&lt;soap:Body&gt; .....

However, with the Delphi 7 SOAP header, the encoding head is not included, as follows:

POST /TesteService/ServicoAgente.asmx HTTP/1.1
SOAPAction: "http://example.com/ValidarTransacao"
Content-Type: text/xml
User-Agent: Borland SOAP 1.2
Host: 192.168.254.1
Content-Length: 1548
Connection: Keep-Alive
Cache-Control: no-cache

<?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"&gt;&lt;SOAP-ENV:Body&gt; .....

Included as a parameter, inside the SOAP Body, is my XML with some non-ascii characters that appears as ?? inside the C# Web Service after I receive the method from the Delphi client, and this seems to me the only logical explanation. When I check the XML in Delphi right before I send it, it's perfectly encoded but, on the receiving end, I get ??.
On the unit imported using WSDL importer, it specifies utf-8, as you can see below:

initialization
  InvRegistry.RegisterInterface(TypeInfo(TesteAgentSoap), 'http://example.com/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(TesteAgentSoap), 'http://example.com/%operationName%');
  InvRegistry.RegisterInvokeOptions(TypeInfo(TesteAgentSoap), [ioDefault, ioDocument, ioHasReturnParamNames, ioHasNamespace]);

end.

What can I do to change the encoding of the XML for the SOAP envelope? Any ideas what else could be wrong? I seems logical to me that, if the XML for the SOAP envelope is not correctly encoded as utf-8, then my XML inside this XML won't be correctly read
Tks so much for your time

A: 

If I understand you correctly you are trying to figure out how to add the string utf-8 to your SOAP envelope? I'm afraid I dont think its that simple (but to be sure you could many change a soap XML stream and test it).

Delphi prior to Delphi 2009 was not Unicode compliant and so would not encode items going out as UTF-8 since delphi itself was not. Some european characters can be represented fine within delphi but externally its anyones guess.

Your best bet is to update to a version of Delphi that is Unicode compliant or if thats not possible use a Delphi unicode library such as TNT.

Toby Allen
Toby, even though I'm using only WideStrings for string manipulation?
Pascal
Delphi 6 (or even 5) has a Utf8Encode function. Old Delphi versions are not that bad :)
mjustin
If it ever goes through a non-unicode delphi function you will loose all info, its possible but a bit risky.
Toby Allen
+2  A: 

If you use HTTPRio / HTTPWebNode maybe this helps:

  • set HTTPRIO.Converter.Options.soUTF8InHeader to True
  • set HTTPWebNode.UseUTF8InHeader to True

(found here)

mjustin
You're awesome! I looked everywhere! Tks so much
Pascal