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

Delphi调用C#编写的WebService参数为Null解决方法

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
今天测试.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.
至此问题搞定了。
 
但是经过我的测试发现,还是不行.......找到了其他原因问题
解决了,


在用VS2005写的WebService的类属性中加入SoapRpcServiceAttribute属性就可以了。
如 下:
  [SoapRpcService(RoutingStyle=SoapServiceRoutingStyle.SoapAction)]

鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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