【转】Delphi调用webservice总结
Delphi调用C#写的webservice
用delphi的THTTPRIO控件调用了c#写的webservice。
下面是我调试时遇到的一些问题:
1:导入wsdl文件:file--new----other----webservice---WSDLimporter---输入wsdl地址:如下: WebService/WebServiceCall.asmx?wsdl
注意末尾的:‘?wsdl‘不能少。要不可能会说找不到。
2:设置THTTPRIO控件的属性:
把 127.0.0.1 /WebService/WebServiceCall.asmx?wsdl赋给URL属性,而不是赋给wsdlLocation属性。
3:传递参数是web服务端总为空:
在导入的接口单元的声明部分添加如下代码:
InvRegistry.RegisterInvokeOptions(TypeInfo(Service1Soap),ioDocument);//其中红色部分为导入接口名称。
在IIS中配置C#写的webservice,有时候会出现如下的错误:
--------------------------------------------------------
分析器错误消息: 在应用程序级别之外使用注册为 allowDefinition=‘MachineToApplication‘ 的节是错误的。如果在 IIS中没有将虚拟目录配置为应用程序,则可能导致此错误。
源错误:
安全身份验证模式。
-->
<authentication mode="Windows"/>
<!--
如果在执行请求的过程中出现未处理的错误
------------------------------------------------------------------------------
解决方法:
在要发布的虚拟目录中的创建一个应用程序。步骤
你的站点 --> 选中你要发布的虚拟目录 --> 右键单击 --> 属性 --> 目录(选项卡) --> 应用程序名 --> 创建 --> 确定。
然后再重新访问页面,应该就OK了。
Delphi 7 建立测试程序
1、新建一个应用程序:
2、拖一个button一个edit和一个HTTPRIO(在webservices页上)到窗体上;
3、接下来:
File-> new-> other-> webservices-> WSDL importer
输入wsdl文件地址,点击next 导入
保存unit Service1
4、在unit1(form1 的单元文件)中引用Service1
5、 HTTPRIO1的 URL属性设置为 ‘?WSDL ‘
6、添加form1 的代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, InvokeRegistry, Rio, SOAPHTTPClient;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
HTTPRIO1: THTTPRIO;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
Service1;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:=(HTTPRIO1 as Service1Soap).HelloWorld;
end;
end.
如果有时候测试发现,还是不行.......可能有下面的问题,
在用VS2005写的WebService的类属性中加入SoapRpcServiceAttribute属性就可以了。
如 下:
[SoapRpcService(RoutingStyle=SoapServiceRoutingStyle.SoapAction)]
Delphi开发和调用的webservice
下面说明如何编写用于IIS发布的ISAPI类型的WebService。
1、 New|Other|WebServices|SOAP Server Application|这里先选择建立Web App Debugger类型的WebService,因为这种类型的WebService便于调试,,当我们调试好它,准备发布时再将此类型转换为ISAPI类型。
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/67558.html