第二步:将webserivce的WSDL导入到该dll工程中,如何导,方法至少有两种,我说简单的一种: 

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(二)的更多相关文章

  1. 教程-Delphi 调用控制面板设置功能

    应用程序运行时,有时需要对系统环境有特殊要求.例如,在Delphi数据库应用程序中可能需要进行BDE(Borland Database Engine)或ODBC数据源名称(DSN:Data Sourc ...

  2. 教程-Delphi调用百度地图API(XE8+WIN7)

    unit U_map; interface //---------------------------------------------------// //----------COPY BY 无言 ...

  3. 【转】Delphi调用webservice总结

    原文:http://www.cnblogs.com/zhangzhifeng/archive/2013/08/15/3259084.html Delphi调用C#写的webservice 用delph ...

  4. Delphi调用webservice总结

    Delphi调用webservice总结     Delphi调用C#写的webservice 用delphi的THTTPRIO控件调用了c#写的webservice. 下面是我调试时遇到的一些问题: ...

  5. delphi调用java编写的webservice

    delphi调用java编写的webservice JAVApojo: public class GroupInfo implements Serializable{    private stati ...

  6. delphi 调用Webservice 引入wsdl 报错 document empty

    delphi 调用Webservice 引入wsdl 报错 document empty 直接引入wsdl 地址报错 document empty 解决办法:在浏览器里保存为xml文件,然后在开发环境 ...

  7. Delphi调用JAVA的WebService上传XML文件(XE10.2+WIN764)

    相关资料:1.http://blog.csdn.net/luojianfeng/article/details/512198902.http://blog.csdn.net/avsuper/artic ...

  8. Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示

    Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示 在 开发中遇到应用c#及asp.net的在的webservice 保存图片并以xml文件形式现实出来 ...

  9. java获取https网站证书,附带调用https:webservice接口

    一.java 获取https网站证书: 1.创建一个java工程,新建InstallCert类,将以下代码复制进去 package com; import java.io.BufferedReader ...

随机推荐

  1. C# 操作mongodb 分组

    c#操作mongodb的分组的简单例子: 1.首先要下载c#对应的mongodb驱动,官方下载地址:https://github.com/mongodb/mongo-csharp-driver/rel ...

  2. unity博文搜集

    一.综合篇 1. 脚本 unity3d脚本编程基础 2.Mecanim 使用Mecanim实现连击 3. 数学图形学 U3D需要用到的数学基础  2 4. shader 猫都能学会的Unity3D S ...

  3. Universal Asynchronous Receiver/Transmitter

    USART簡介與特性 NRZ標準資料格式(Mark/Space) 半雙工/全雙工 Synchronous 同步傳輸 CLOCK SKEW Asynchronous 非同步傳輸 半/全雙工.同步/非同步 ...

  4. 使用Sqoop从mysql向hdfs或者hive导入数据时出现的一些错误

    1.原表没有设置主键,出现错误提示: ERROR tool.ImportTool: Error during import: No primary key could be found for tab ...

  5. in on at 总结

    in,on,at的时间用法和地点用法 一.in, on, at的时间用法 ①固定短语: in the morning/afternoon/evening在早晨/下午/傍晚, at noon/night ...

  6. HTML <!--...--> 注释标签

    HTML <!--...--> 注释标签 实例 HTML 注释: <!--这是一个注释,注释在浏览器中不会显示--> <p>这是一个段落</p>   浏 ...

  7. error opening registry key software/javasoft/java runtime environment

    些问题是由于多个版本java相互冲突,查看环境变量,删除其中一个即可.1.把Path里的%JAVA_HOME%\bin;放到最前面就可以,解决了给分! 2.是因为文件夹“%SystemRoot%\sy ...

  8. bzoj1084

    乍一看这题好难,根本不会: 直到看到1<=m<=2…… 显然分类讨论dp, 很快想到这题的dp和poj2430相类似 m=2的时候f[i,j,k]表示到第i行用了j个矩阵结尾状态为k时最大 ...

  9. CodeForces 400

    A - Inna and Choose Options Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d &a ...

  10. grb文件的读取

    grb文件的读取(转自:http://blog.sciencenet.cn/blog-922140-713837.html) read_grib.r4.rar 今天来斟酌了下grb文件格式的读取,现在 ...