Soap Envelope Header in Delphi 7 not including utf

2019-07-19 11:04发布

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"><soap:Body> .....

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"><SOAP-ENV:Body> .....

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

2条回答
手持菜刀,她持情操
2楼-- · 2019-07-19 11:42

If you use HTTPRio / HTTPWebNode maybe this helps:

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

(found here)

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-07-19 11:48

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.

查看更多
登录 后发表回答