教程-Delphi调用C# WEBSERVICE(二)
file->new->other->WebService->WSDL Importer,(将C#的WSDL输入)然后delphi会自动给你生成了一个pas文件,
(比如我们当前例子的服务地址是:http://localhost/AttributeTesting/AttributeTesting.asmx
如果你想输入WSDL那么就是http://localhost/AttributeTesting/AttributeTesting.asmx?wsdl)
function GetServiceSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ServiceSoap;
const
defWSDL = ’http://localhost/webserver/Service.asmx?WSDL’;
defURL = ’http://localhost/webserver/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
//RIO.HTTPWebNode.UseUTF8InHeader:=True; //
在此添加一句,修改编码方案。
Result := (RIO as ServiceSoap);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
RIO.HTTPWebNode.UseUTF8InHeader:=True;//如果出现乱码对于中文参数必须加上
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;
initialization
InvRegistry.RegisterInterface(TypeInfo(ServiceSoap), ’http://localhost/webserver/’, ’utf-8’);
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceSoap), ’http://localhost/webserver/%operationName%’);
//对于无法识别传入的参数的问题,需要手工加上下面这一句>......
InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);
3.使用delphi调用上面的dll
就一个函数,没有什么好说的:
procedure TForm1.Button1Click(Sender: TObject);
type
GetNumTotal=function(a,b:integer):integer;stdcall;
var
Th:Thandle;
Tf:GetNumTotal;
Tp:TFarProc;
begin
Th:=LoadLibrary(’mywebservice.dll’); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar(’GetNum’));
if Tp<>nil
then begin
Tf:=GetNumTotal(Tp);
Edit1.Text:=IntToStr(Tf(1,3)); {调用GetNumTotal函数}
end
else
ShowMessage(’GetNumTotal函数没有找到’);
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage(’mywebservice.dll没有找到’);
end;
public static extern int GetNum(int a, int b);
private void button1_Click(object sender, EventArgs e)
{
int a,b,i;
a=10;
b =20;
i=GetNum(a,b); //第一次比较慢(webserivce的唯一弊端!!!!)
textBox1.Text = i.ToString();
}
教程-Delphi调用C# WEBSERVICE(二)的更多相关文章
- 教程-Delphi 调用控制面板设置功能
应用程序运行时,有时需要对系统环境有特殊要求.例如,在Delphi数据库应用程序中可能需要进行BDE(Borland Database Engine)或ODBC数据源名称(DSN:Data Sourc ...
- 教程-Delphi调用百度地图API(XE8+WIN7)
unit U_map; interface //---------------------------------------------------// //----------COPY BY 无言 ...
- 【转】Delphi调用webservice总结
原文:http://www.cnblogs.com/zhangzhifeng/archive/2013/08/15/3259084.html Delphi调用C#写的webservice 用delph ...
- Delphi调用webservice总结
Delphi调用webservice总结 Delphi调用C#写的webservice 用delphi的THTTPRIO控件调用了c#写的webservice. 下面是我调试时遇到的一些问题: ...
- delphi调用java编写的webservice
delphi调用java编写的webservice JAVApojo: public class GroupInfo implements Serializable{ private stati ...
- delphi 调用Webservice 引入wsdl 报错 document empty
delphi 调用Webservice 引入wsdl 报错 document empty 直接引入wsdl 地址报错 document empty 解决办法:在浏览器里保存为xml文件,然后在开发环境 ...
- Delphi调用JAVA的WebService上传XML文件(XE10.2+WIN764)
相关资料:1.http://blog.csdn.net/luojianfeng/article/details/512198902.http://blog.csdn.net/avsuper/artic ...
- Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示
Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示 在 开发中遇到应用c#及asp.net的在的webservice 保存图片并以xml文件形式现实出来 ...
- java获取https网站证书,附带调用https:webservice接口
一.java 获取https网站证书: 1.创建一个java工程,新建InstallCert类,将以下代码复制进去 package com; import java.io.BufferedReader ...
随机推荐
- Intel HEX file结构
https://en.wikipedia.org/wiki/Intel_HEX 1, Intel Hex每行的组成 开始标志+Byte数+地址+数据类型+数据+Checksum 2, 开始标志 冒号: ...
- Grails的redirect无法跳转时的一个可能原因
由于controller的命名一般首字母大写,如Login 此时如 class LoginController { def index = { redirect(action:Login, param ...
- Ubuntu14.04下Unity桌面托盘图标显示问题
本来想丰富一下功能,遂开始安装大开眼界:Ubuntu下10个厉害的Indicator小程序这里的Indicator小程序. 很不幸,在安装到indicator-multiload的时候,准备注销看一下 ...
- 转载:redis备份策略
Redis提供了两种持久化选项,分别是RDB和AOF. 默认情况下60秒刷新到disk一次[save 60 10000 当有1w条keys数据被改变时],Redis的数据集保存在叫dump.rdb一个 ...
- [topcoder]IncrementAndDoubling
http://community.topcoder.com/stat?c=problem_statement&pm=12790&rd=15708 这道题只有两个操作,一是加一,二是数组 ...
- AVPicture、AVFrame和AVPacket
http://blog.csdn.net/ym012/article/details/6540065 从定义上可知,AVPicture是AVFrame的一个子集,他们都是数据流在编解过程中用来保存数据 ...
- Log4delphi使用心得
因为delphi不是我的主力开发工具,所有一直没有使用一个正式的日志组件.偶尔要记日志时,就复制同事的一个简单的文件日志函数.现在又要用到delphi日志了,决定找个通用的日志组件,造福共事的Delp ...
- 《深入理解linux内核》第二章 内存寻址
三种不同的内存地址 逻辑地址(logical address)包含在linux实际指令中的地址,即分段式地址,是对应的硬件平台段式管理转换前地址由16位的段选择符(segment selector)和 ...
- c++模板实现抽象工厂
类似于rime的rime::Class<factory type, product type>实现方式. C++模板实现的通用工厂方法模式 1.工厂方法(Factory Method)模式 ...
- ActionBar官方教程(4)给ActionBar添加操作项及它们的事件处理
Adding Action Items The action bar provides users access to the most important action items relating ...