delphi调用C#webservice接口的中文编码问题

来源:互联网 发布:网络赚小钱 编辑:程序博客网 时间:2024/05/22 13:28

在webservice是用的utf-8需要在生成的接口中添加:

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;
  RIO.Converter.Encoding := 'UTF-8';
  RIO.Converter.Options := RIO.Converter.Options + [soUTF8InHeader,soUTF8EncodeXML];

  try
    Result := (RIO as YouGuessServiceSoap);
    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;



initialization
  InvRegistry.RegisterInterface(TypeInfo(YouGuessServiceSoap), 'http://localhost:8080/', 'utf-8');
  InvRegistry.RegisterInvokeOptions(TypeInfo(YouGuessServiceSoap),ioDocument);
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(YouGuessServiceSoap), 'http://localhost:8080/%operationName%');


end. 

0 0
原创粉丝点击