最近项目中需要用Delphi调用C# .Net 2.0 webService, 根据一些通用的办法, 很快把.net 的DataSet数据集的数据提取出来了, 但是在更新数据的服务中插入数据一直不能成功, 在Delphi传入的参数根本无法进入web service中, 也就是说传入的其实就是空值.
在网上找了好多资料, 什么在类接口文件中加入 InvRegistry.RegisterInvokeOptions(TypeInfo(LicenseInfoSoap), ioDocument);,
设置属性 RIO.Converter.Options :=RIO.Converter.Options + [soUTF8InHeader,soUTF8EncodeXML,soLiteralParams] 之类的, 这些统统都是扯淡, 根本不需要在Delphi中进行处理的, 问题就不在Delphi上.
很简单只需要在C#的webService文件中引入 using System.Web.Services.Protocols;命名空间, 加入属性 [SoapRpcService(RoutingStyle = SoapServiceRoutingStyle.SoapAction)] . 再把WebServiceBinding属性调整一下, 换成 [WebServiceBinding(ConformsTo = WsiProfiles.None)]就大功告成了. 最后的 属性代码段 如下所示:
[WebService(Namespace = "http://tempuri.org/")]
// [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[SoapRpcService(RoutingStyle = SoapServiceRoutingStyle.SoapAction)]
[System.ComponentModel.ToolboxItem(false)]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
还有一种简易调用WebService的方法:
var
SoapClient: OleVariant;
begin
SoapClient := CreateOleObject('MSSOAP.SoapClient');
SoapClient.mssoapinit('http://localhost/ws/Service1.asmx?wsdl');
showmessage(SoapClient.GenQRCode(Trim(LotSN.Text), Trim(InputInfo.Text)));
end;