• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

用Delphi7调用.NET2.0的WebService所要注意的问题(Document格式和UTF8编码) ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

      Delphi7 调用VS.NET 2005开发的基于.NET 2.0的WebService时发生了错误。查阅资料 http://www.community.borland.com/article/borcon/files/4132/paper/4132.html 发现原来Delphi7客户端虽然支持WebService的RPC|Encoded 和 Document|Literal编码,但 默认的是使用RPC。而.NET 2.0下的WebService却是默认采用Documnet|Literal编码的。因此我们需要显示地声明让Delphi客户端采用Documnet|Literal编码就可以了。在Delphi的WSDL Importer产生了WebService的接口文件中加入如下行:

initialization
  InvRegistry.RegisterInterface(TypeInfo(ServiceSoap), 'http://tempuri.org/', 'utf-8');
  InvRegistry.RegisterInvokableClass(ServiceSoapImpl);
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceSoap), 'http://tempuri.org/HelloWorld');
  InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);//指明Delphi采用Document编码
end. 


如果需要在WebService中传送汉字的参数,则建议在Service.pas中再添加一行代码

function GetServiceSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ServiceSoap;
const
  defWSDL = 'http://localhost/myservice/service.asmx?wsdl';
  defURL  = 'http://localhost/myservice/service.asmx';
  defSvc  = 'Service';
  defPrt  = 'ServiceSoap';
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;  //添加该行,指定采用UTF-8代码传输
  try
    Result := (RIO as ServiceSoap);
    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;


需要说明的是使用Delphi2006则不需要上述的改变即可以正确调用VS.NET 2005书写的WebService.

http://www.cnblogs.com/sonicit/archive/2007/06/02/768753.html

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap