Ao consumir em Delphi win32 Webservices escritos em Delphi .Net 1.1(e noutras plataformas também), podem ocorrer erros relacionados com caracteres acentuados e cedilhados.
Por exemplo ao tentar enviar este tipo de caracteres, estes podem não ser interpretados e aparecer no seu lugar outros símbolos (??##). Ocorre porque no SOAP interface criado a partir do WSDLImporter não fica especificado o Encoding correcto e ao ser criado SOAP Envelope este converte os caracteres noutro simbolo.
Para o fazer devemos explicitamente declarar o uso de um encoding no Header do SOAP Envelope. No HTTPRio:
HTTPRIO.HTTPWebNode.UseUTF8InHeader := True ;
excerto de interface criado por WSDLImporter:
function GetTws1Soap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): Tws1Soap;
const
defWSDL = 'http://servidor.com/ws/ws1.asmx?WSDL';
defURL = 'http://servidor.com/ws/ws1.asmx';
defSvc = 'Tws1';
defPrt = 'Tws1Soap';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
RIO.HTTPWebNode.UseUTF8InHeader := True ; //adicionar esta linha
try
Result := (RIO as Tws1Soap);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;
OU
object HTTPRIO: THTTPRIO
OnAfterExecute = HTTPRIOAfterExecute
OnBeforeExecute = HTTPRIOBeforeExecute
URL = 'http://localhost:3972/WS_SysConsig/Service.asmx'
HTTPWebNode.Agent = 'Borland SOAP 1.2'
HTTPWebNode.UseUTF8InHeader = True
HTTPWebNode.InvokeOptions = [soIgnoreInvalidCerts, soAutoCheckAccessPointViaUDDI]
Converter.Options = []
Converter.Encoding = 'utf-8'
Left = 24
Top = 24
end
Note:
Some Web Services (such as Apache or .NET) require transport level encoding rather than DOM level encoding. In such cases, it is possible that setting Encoding can cause problems because the Web Service converts characters at the transport level and then converts a second time because of the encoding attribute that Encoding adds to the XML representation. If a Web Service requires transport-level encoding and assumes UTF8, Encoding should be an empty string and the Options property should include soUTF8EncodeXML and soUTF8InHeader.