前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >.NET 2.0 Web Services的bug?

.NET 2.0 Web Services的bug?

作者头像
用户3135539
发布2018-09-12 11:47:39
5960
发布2018-09-12 11:47:39
举报
文章被收录于专栏:

今天测试.net 2.0的WebService,发现了一个大问题。就是无法获取参数,参数永远是null。当然了使用.net调用没有任何问题,web测试页也正常。不论是Delphi7还是java调用的结果的都是一样的,难道是.net 2.0的Bug? 测试结果发现:值类型参数全部为缺省值,引用类型全部为null WebService的代码如下:

    [WebMethod] public string EchoString(string args)     { return args;     }     [WebMethod] public string EchoInt(int args)     { return args.ToString();     }

delphi调用的代码

procedure TForm1.Button3Click(Sender: TObject); var   ss:ServiceSoap;   hello:WideString; begin try     HTTPRIO1.WSDLLocation := edtAddress.Text;     HTTPRIO1.Service := edit3.Text;     HTTPRIO1.Port := edit4.Text;     ss := (HTTPRIO1 as ServiceSoap);     hello:= 'hello';     Memo1.Lines.Add(ss.EchoInt(234));   except     on e : exception do           showmessage(e.Message);   end; end;

-------------------------------------------------------------------------------------------------------------------------------------------------- 在不断尝试中发现vs2003生成的web Services,delphi调用的时候不会有任何问题,即使是delphi2006也无法正常调用.net 2.0的Web Service. 最后经过不懈努力,终于找到方法那就是在delphi生成webservices声明单元中加入以行 InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument); 如:

unit Service; interface uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns; type   ServiceSoap = interface(IInvokable)   ['{77573149-9C57-FA51-F11F-EFD527C91BD9}']     function  HelloWorld(const asdf: WideString): WideString; stdcall;   end; implementation type   ServiceSoapImpl = class(TInvokableClass, ServiceSoap) public     { ServiceSoap }     function  HelloWorld(const asdf: WideString): WideString; stdcall;   end; function ServiceSoapImpl.HelloWorld(const asdf: WideString): WideString; begin   { TODO - Implement method HelloWorld } end; 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);//就是这一行 end. 

至此问题搞定了。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2006-04-27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档