delphi用webservice
delphi的webservice开发。
一、在已有的项目中,调用外部的webservice
1、根据向导建webservice,在项目中引入“WSDL Importer"。假设引入后生成的类的名字为”service"


2、对生成的service类做相应的修改。
2.1、如果webservice方法里的某些参数即是接收传入参数又是接收返回参数,在delphi里要对参数名字重新命名
如在用c#写的webservice的服务端方法是sr.Get_Delivery_Data_Over(sn, sjlx, ref err);
//默认生成的代码为
procedure Get_Delivery_Data(const err: WideString; const data_str: TByteDynArray; const sn: Integer; const sjlx: WideString; out Get_Delivery_DataResult: Boolean; out err: WideString; out data_str: TByteDynArray; out sn: Integer); stdcall;
///要改成如下:
procedure Get_Delivery_Data(const err1: WideString; const data_str1: TByteDynArray; const sn1: Integer; const sjlx: WideString; out Get_Delivery_DataResult: Boolean; out err: WideString; out data_str: TByteDynArray; out sn: Integer); stdcall;
2.2、 如果delphi调用c#写的webservice时,服务器端方法接收到delphi传过来的参数总是为空时,在delphi的service类的initialization下面加这名话
InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap),ioDocument); ///必需要加,不然传到c#写的webservice里的方法的参数值是空的
如下是service类的源代码
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://fti.yndzyf.com/Service.asmx?wsdl
// Encoding : utf-
// Version : 1.0
// (-- :: - 1.33.2.5)
// ************************************************************************ // unit Service; interface uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns; type // ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Borland types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:string - "http://www.w3.org//XMLSchema"
// !:base64Binary - "http://www.w3.org//XMLSchema"
// !:int - "http://www.w3.org//XMLSchema"
// !:boolean - "http://www.w3.org//XMLSchema" Websoap = class; { "http://aitf.yndzyf.com/"[H] } // ************************************************************************ //
// Namespace : http://aitf.yndzyf.com/
// ************************************************************************ //
Websoap = class(TSOAPHeader)
private
FUserName: WideString;
FPassWord: WideString;
published
property UserName: WideString read FUserName write FUserName;
property PassWord: WideString read FPassWord write FPassWord;
end; // ************************************************************************ //
// Namespace : http://aitf.yndzyf.com/
// soapAction: http://aitf.yndzyf.com/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : ServiceSoap
// service : Service
// port : ServiceSoap
// URL : http://fti.yndzyf.com/Service.asmx
// ************************************************************************ //
ServiceSoap = interface(IInvokable)
['{E00EB65B-7136-E473-42EF-D3135F25019F}']
procedure Get_Delivery_Data(const err1: WideString; const data_str1: TByteDynArray; const sn1: Integer; const sjlx: WideString; out Get_Delivery_DataResult: Boolean; out err: WideString; out data_str: TByteDynArray; out sn: Integer); stdcall;
procedure Get_Delivery_Data_Over(const sn: Integer; const sjlx: WideString; const err1: WideString; out Get_Delivery_Data_OverResult: Boolean; out err: WideString); stdcall;
procedure Receive_data(const error1: WideString; const str: TByteDynArray; const sn: Integer; const sjlx: WideString; out Receive_dataResult: Boolean; out error: WideString); stdcall;
end; function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil;user:string='';password:string=''): ServiceSoap; implementation function GetServiceSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO;user:string;password:string): ServiceSoap;
const
defWSDL = 'http://fti.yndzyf.com/Service.asmx?wsdl';
defURL = 'http://fti.yndzyf.com/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;
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; initialization
InvRegistry.RegisterInterface(TypeInfo(ServiceSoap), 'http://aitf.yndzyf.com/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceSoap), 'http://aitf.yndzyf.com/%operationName%');
InvRegistry.RegisterHeaderClass(TypeInfo(ServiceSoap), Websoap, 'Websoap', '');
RemClassRegistry.RegisterXSClass(Websoap, 'http://aitf.yndzyf.com/', 'Websoap');
InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap),ioDocument); ///必要要加,不然传到c#写的webservice里的值是空的
end.
3、调用
procedure Tform_smrk.bgetydClick(Sender: TObject);
var sql:string;
var err_fp,err1_fp,err_yjm,err1_yjm:Widestring;
data_fp,data_fp1,data_yjm,data_yjm1:TByteDynArray;
sn_fp,sn_fp1,sn_yjm,sn_yjm1:Integer;
flag_fp,flag_fp1,flag_yjm,flag_yjm1:boolean;
ws:webSoap;
svc:serviceSoap;
begin
svc := HTTPRIO1 as ServiceSoap;
ws:=websoap.Create;
ws.UserName:=serviceName;///webservice的用户名和密码
ws.PassWord:=servicePassword;
(svc as ISOAPHeaders).Send(ws);
svc.Get_Delivery_Data('',data_fp1,,'运单',flag_fp,err_fp,data_fp,sn_fp);
(svc as ISOAPHeaders).Send(ws);///每次调用时都要重新设置用户和密码
svc.Get_Delivery_Data('',data_yjm1,,'电子监管',flag_yjm,err_yjm,data_yjm,sn_yjm);
if length(data_fp)> then///如果有运单
begin
ADOStoredProc1.ProcedureName:= 'p_insert_data';
ADOStoredProc1.Parameters.Clear;
ADOStoredProc1.Parameters.Refresh;
ADOStoredProc1.Parameters.ParamByName('@data_str').Value:=data_fp;
if length(data_yjm)> then ADOStoredProc1.Parameters.ParamByName('@data_str_yjm').Value:=data_yjm;
ADOStoredProc1.Prepared;
ADOStoredProc1.ExecProc;
end
要注意的是:1、每次调用webservice时要重新写一次(svc as ISOAPHeaders).Send(ws);,将webSoap和serviceSoap关联
2、上面的代码是从webservice取xml的二进制文件,然后将取出的二进制数据传入到存储过程p_insert_data里。用ADOStoreProc可以对存储过程传参数
时可以不考虑参数的类型,直接用ADOStoredProc1.Parameters.ParamByName('@data_str').Value:=data_fp赋值,在赋值前要ADOStoredProc1.Parameters.Refresh;不然不能对参数 赋值成功。
3、HTTPRIO1 是控件THTTPRIO。控件要设置好URL=http://fti.yndzyf.com/Service.asmx?wsdl
delphi用webservice的更多相关文章
- Delphi调用webservice总结
Delphi调用webservice总结 Delphi调用C#写的webservice 用delphi的THTTPRIO控件调用了c#写的webservice. 下面是我调试时遇到的一些问题: ...
- delphi 调用Webservice 引入wsdl 报错 document empty
delphi 调用Webservice 引入wsdl 报错 document empty 直接引入wsdl 地址报错 document empty 解决办法:在浏览器里保存为xml文件,然后在开发环境 ...
- Delphi编写WebService体会
源:Delphi编写WebService体会 Dispatch: 派遣,分派 Invoke: 调用 Invokable: 可调用接口 TReomtable: WebService中自定义类都是继承自该 ...
- DELPHI新版本WEBSERVICE的变化
DELPHI新版本WEBSERVICE,不仅可以编译成ISAPI DLL,依靠IIS部署, 并且还可以编译成单独的EXE,不再依赖IIS就可以独立运行,这一点未尝不可以说是非常方便的改进.
- Delphi调用WebService(通过SoapHeader认证)经验总结
项目(Delphi开发)需要调用另一个系统的WebService.走了不少弯路,现记录总结一下经验.以下是WebService要求: 1.WebService概述 营销Webservice接口采用Ap ...
- 【转】Delphi调用webservice总结
原文:http://www.cnblogs.com/zhangzhifeng/archive/2013/08/15/3259084.html Delphi调用C#写的webservice 用delph ...
- Delphi实现WebService带身份认证的数据传输
WebService使得不同开发工具开发出来的程序可以在网络连通的环境下相互通信,它最大的特点就是标准化(基于XML的一系列标准)带来的跨平台.跨开发工具的通用性,基于HTTP带来的畅通无阻的能力(跨 ...
- Delphi 调试WEBService程序(ISAPI或CGI) 把Web App Debugger executable转换成 ISAPI/NSAPI
1.新建一个web工程,请选中最下面一项:Web App Debugger executable,Coclass name我们设为demo1: 2.在弹出的WebModule2中右击,在弹出的Ac ...
- delphi调用webservice 转
如今 Web Service 已越来越火了,在DotNet已开发的Web Service中,Delphi 7如何方便的调用DotNet写的Web Service呢?方法有两种,一种是在Delphi ...
随机推荐
- 《Linux调优工具oprofile的演示分析》
根据CPU架构oprofile采样的触发有两种模式:1) NMI模式: 利用处理器的performance counter功能, 指定counter的类型type和累进数量count. 比如 type ...
- 哈希表(散列)HashTable实现
近期刷Leetcode发现凡是找字符串中反复字符或者数组中找反复数据的时候就不知道从何下手了. 所以决定学习一下哈希表解题.哈希表的原理主要是解决分类问题,hash表是介于链表和二叉树之间的一种中间结 ...
- 25个增强iOS应用程序性能的提示和技巧(0基础篇)
在开发iOS应用程序时,让程序具有良好的性能是非常关键的. 这也是用户所期望的,假设你的程序执行迟钝或缓慢,会招致用户的差评.然而因为iOS设备的局限性,有时候要想获得良好的性能,是非常困难的. 在开 ...
- All-In-One方式-安装openstack
ALL-IN-ONE安装openstack******************************************************************************* ...
- 关于IntelliJ IDEA有时候快捷键无效的说明
1.这个原因最大的因素可能就是 搜狗输入法了, 关闭搜狗输入法,ok, 2.也可能是qq快捷键冲突,关闭它. 3.也可能是搜狗输入法快捷键冲突,关闭它.
- Pycharm配置(二)
1.主题 这部分教程主要介绍如何创建一个Python工程并使其具有Pycharm的代码风格.你将会看到Pycharm使你的源码变得非常简洁美观,带有合适的缩进.空格等等,因此Pycharm也是一款代码 ...
- iOS 讯飞语音测试没问题,一上线就用不了了
看一下打包的版本是不是release, Debug : 调试版本,主要是让程序员使用,在调试的过程中调用 Debug 会启动更多的服务来监控错误,运行速度相对较慢,而且比较耗能. Release : ...
- mkpasswd 随机密码生成
root@op-admin:~# mkpasswd -l -n usage: mkpasswd [args] [user] where arguments are: -l # (length of p ...
- ABP PUT、DELETE请求错误405.0 - Method Not Allowed 因为使用了无效方法(HTTP 谓词) 引发客户端错误 No 'Access-Control-Allow-Origin' header is present on the requested resource
先请检查是否是跨域配置问题,请参考博客:http://www.cnblogs.com/donaldtdz/p/7882225.html 一.问题描述 ABP angular前端部署后,查询,新增都没问 ...
- Ubuntu上安装flashplayer
当你已经为linux flashplayer无法安装抓狂的时候,不妨来看看吧 我使用的是Ubuntu 12.04.4 LTS,由于firefox无法播放flash所以去下载了一个adobeflashp ...