DelphiXE7中创建WebService(服务端+客户端) good
相关资料:http://www.2ccc.com/news/Html/?1507.html
DelphiXE7新建WebService具体操作:
1.打开“DelphiXE7”->“File”->“New”->“Other”
2.“New Items”->“Delphi Projects”->“WebSrvice”->“SOAP Server Application”
3.“Stand-alone application”->“Next”
4.“VCL application”->“Next”
5.“8080”->“Finish”
6.“Create Interface for SOAPmodule?”->“Yes”
7.“Add New WebService”->输入服务名字“MyData”->“OK”
8.保存全部工程文件
9.在“WebModuleUnit1”单元中放入控件:
FDConnection1
FDPhysMSSQLDriverLink1
FDQuery1
DataSetProvider1
ClientDataSet1
10.双击FDConnection1->Definition->Driver ID:->“MSAcc”->Daabase->“E:\MyData.mdb”->LoginPrompt:=False->Connected:=True
11.FDQuery1->Connection:=FDConnection1->SQL:=“select * from usesr”->Active:=True
12.DataSetProvider1->DataSet:=FDQuery1
13.ClientDataSet1->ProvideName:=DataSetProvider1
服务端-实例代码:

1 unit WebModuleUnit1;
2
3 interface
4
5 uses System.SysUtils, System.Classes, Web.HTTPApp, Soap.InvokeRegistry,
6 Soap.WSDLIntf, System.TypInfo, Soap.WebServExp, Soap.WSDLBind, Xml.XMLSchema,
7 Soap.WSDLPub, Soap.SOAPPasInv, Soap.SOAPHTTPPasInv, Soap.SOAPHTTPDisp,
8 Soap.WebBrokerSOAP, FireDAC.Stan.Intf, FireDAC.Stan.Option,
9 FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
10 FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MSAcc,
11 FireDAC.Phys.MSAccDef, FireDAC.Phys.MSSQLDef, FireDAC.Stan.Param,
12 FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, Datasnap.DBClient,
13 Datasnap.Provider, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
14 FireDAC.Phys.ODBCBase, FireDAC.Phys.MSSQL;
15
16 type
17 TWebModule1 = class(TWebModule)
18 HTTPSoapDispatcher1: THTTPSoapDispatcher;
19 HTTPSoapPascalInvoker1: THTTPSoapPascalInvoker;
20 WSDLHTMLPublish1: TWSDLHTMLPublish;
21 FDConnection1: TFDConnection;
22 FDPhysMSSQLDriverLink1: TFDPhysMSSQLDriverLink;
23 FDQuery1: TFDQuery;
24 DataSetProvider1: TDataSetProvider;
25 ClientDataSet1: TClientDataSet;
26 procedure WebModule1DefaultHandlerAction(Sender: TObject;
27 Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
28 private
29 { Private declarations }
30 public
31 function GetInfo: widestring;
32 function SetSQL(ASQL: widestring): widestring;
33 { Public declarations }
34 end;
35
36 var
37 WebModuleClass: TComponentClass = TWebModule1;
38
39 implementation
40
41 {%CLASSGROUP 'Vcl.Controls.TControl'}
42
43 {$R *.dfm}
44
45 function TWebModule1.GetInfo: widestring;
46 begin
47 ClientDataSet1.Close;
48 ClientDataSet1.Open;
49 Result := ClientDataSet1.XMLData;
50 ClientDataSet1.Close;
51 end;
52
53 function TWebModule1.SetSQL(ASQL: widestring): widestring;
54 begin
55 FDQuery1.Close;
56 FDQuery1.SQL.Text := ASQL;
57 try
58 FDQuery1.ExecSQL;
59 Result := '成功 ';
60 except
61 Result := '失败';
62 end;
63 end;
64
65 procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
66 Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
67 begin
68 WSDLHTMLPublish1.ServiceInfo(Sender, Request, Response, Handled);
69 end;
70
71 end.


1 { Invokable interface IMyData }
2
3 unit MyDataIntf;
4
5 interface
6
7 uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns;
8
9 type
10
11 { Invokable interfaces must derive from IInvokable }
12 IMyData = interface(IInvokable)
13 ['{865DBF5C-8DE1-4D01-AE04-16D04A3F5EF0}']
14 function GetInfo:widestring;stdcall;
15 function SetSQL(ASQL: widestring): widestring;stdcall;
16 { Methods of Invokable interface must not use the default }
17 { calling convention; stdcall is recommended }
18 end;
19
20 implementation
21
22 initialization
23 { Invokable interfaces must be registered }
24 InvRegistry.RegisterInterface(TypeInfo(IMyData));
25
26 end.


1 { Invokable implementation File for TMyData which implements IMyData }
2
3 unit MyDataImpl;
4
5 interface
6
7 uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns, MyDataIntf;
8
9 type
10
11 { TMyData }
12 TMyData = class(TInvokableClass, IMyData)
13 public
14 function GetInfo:widestring;stdcall;
15 function SetSQL(ASQL: widestring): widestring;stdcall;
16 end;
17
18 implementation
19 uses WebModuleUnit1;
20
21 { TMyData }
22
23 function TMyData.GetInfo: widestring;
24 var
25 oDM: TWebModule1;
26 begin
27 oDM := TWebModule1.Create(nil);
28 result := oDM.GetInfo;
29 oDM.Free;
30 end;
31
32 function TMyData.SetSQL(ASQL: widestring): widestring;
33 var
34 oDM: TWebModule1;
35 begin
36 oDM := TWebModule1.Create(nil);
37 result := oDM.SetSQL(ASQL);
38 oDM.Free;
39 end;
40
41 initialization
42 { Invokable classes must be registered }
43 InvRegistry.RegisterInvokableClass(TMyData);
44 end.

DelphiXE7客户端具体操作:
1.打开“DelphiXE7”->“File”->“New”->“Other”
2.“New Items”->“Delphi Projects”->“WebSrvice”->“WSDL Importer”
3.“Import WSDL”->WSDL Source中输入“http://localhost:8080/wsdl/IMyData”->“Next”
4.“Automatic SOAP versioning.(Recommended)”->“Next”
5.默认选项->“Finish”
6.Delphi会自动生成IMyData文件->保存
7.放入控件
ClientDataSet1
DataSource1
DBGrid1
8.DataSource1->DataSet:=ClientDataSet1
9.DBGrid1->DataSource:=DataSource1
客户端-实例代码:

1 unit Unit1;
2
3 interface
4
5 uses
6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
7 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.DBGrids, Data.DB,
8 Datasnap.DBClient, Vcl.StdCtrls;
9
10 type
11 TForm1 = class(TForm)
12 Button1: TButton;
13 ClientDataSet1: TClientDataSet;
14 DataSource1: TDataSource;
15 DBGrid1: TDBGrid;
16 Button2: TButton;
17 Edit1: TEdit;
18 procedure Button1Click(Sender: TObject);
19 procedure Button2Click(Sender: TObject);
20 private
21 { Private declarations }
22 public
23 { Public declarations }
24 end;
25
26 var
27 Form1: TForm1;
28
29 implementation
30 uses IMyData1;
31 {$R *.dfm}
32
33 procedure TForm1.Button1Click(Sender: TObject);
34 var
35 ows: IMyData;
36 s: string;
37 begin
38 ows := GetIMyData(true,'http://localhost:8080/wsdl/IMyData',nil); //参数中可以使用配置的url
39 s := ows.GetInfo;
40 if length(s) <> 0 then
41 ClientDataSet1.xmldata := s;
42 end;
43
44 procedure TForm1.Button2Click(Sender: TObject);
45 var
46 ows:IMyData;
47 s:string;
48 begin
49 ows := GetIMyData(true,'http://localhost:8080/wsdl/IMyData',nil); //参数中可以使用配置的url
50 s := ows.SetSQL('delete from usesr where yonghu=' + QuotedStr('ni2'));
51 if length(s) <> 0 then
52 Edit1.Text := s;
53 end;
54
55 end.

DelphiXE7中创建WebService(服务端+客户端) good的更多相关文章
- DelphiXE7中创建WebService(服务端+客户端)
相关资料: http://www.2ccc.com/news/Html/?1507.html http://www.dfwlt.com/forum.php?mod=viewthread&tid ...
- eclipse使用CXF3.1.*创建webservice服务端客户端以及客户端手机APP(二)
eclipse使用CXF3.1.*创建webservice服务端客户端以及客户端手机APP(二) 接上篇博客,本篇博客主要包含两个内容: 4.使用Android studio创建webservice客 ...
- eclipse使用CXF3.1.*创建webservice服务端客户端以及客户端手机APP(一)
eclipse使用CXF3.1.*创建webservice服务端客户端以及客户端手机APP(一) 本篇博客主要包含五个内容: 1.CXF换将搭建以及eclipse配置CXF. 2.eclipse创建w ...
- [转载]Java创建WebService服务及客户端实现
Java创建WebService服务及客户端实现 Java创建WebService服务及客户端实现
- MyEclipse创建WebService服务端和客户端
1.新建立一个javaWeb项目,一个java类,如图: 2.接下来我们就要将项目中的TestService的这个类生成WebService服务端,选择new Web Service,如图: Next ...
- IDEA创建WebService服务端与客户端
创建服务端 一.file–>new–>project 二.点击next后输入服务端名,点击finish,生成目录如下 三.在 HelloWorld.Java 文件中右击,选 Tools 的 ...
- idea创建WebService服务端和客户端
创建服务端 1.file–>new–>project 2.点击next后输入服务端名,点击finish,生成目录如下 3.在 HelloWorld.Java 文件中右击,选 WebServ ...
- [gRPC] 在 .NET Core 中创建 gRPC 服务端和客户端
gRPC 官网:https://grpc.io/ 1. 创建服务端 1.1 基于 ASP.NET Core Web 应用程序模板创建 gRPC Server 项目. 1.2 编译并运行 2. 创建客户 ...
- JAVA WEBSERVICE服务端&客户端的配置及调用(基于JDK)
前言:我之前是从事C#开发的,因公司项目目前转战JAVA&ANDROID开发,由于对JAVA的各种不了解,遇到的也是重重困难.目前在做WEBSERVICE提供数据支持,看了网上相关大片的资料也 ...
随机推荐
- Fix Windows 7 Msvcp71.dll And Msvcr71.dll Missing Error
Fix Windows 7 Msvcp71.dll And Msvcr71.dll Missing Error Fix Msvcp71.dll And Msvcr71.dll Missing Erro ...
- Windows的TCP协议参数
注册表编辑器:regedit 表项:HKEY_LOCAL_MACHINE\SYSTEM\CurentControlSet\Services\Tcpip\Parameters 窗口扩大因子 & ...
- android的JNI标准 android的NDK
转载的! Java Native Interface (JNI)标准是java平台的一部分,它允许Java代码和其他语言写的代码进行交互.JNI 是本地编程接口,它使得在 Java 虚拟机 (VM) ...
- MVC与WebForm的简单的比较
MVC与WebForm的简单的比较 ASP 强制程序员将业务逻辑和展示页放到一个文件中 WebForm 允许程序员将业务逻辑与页面展示分开到不同的文件中,并且提供强大的开发平台来写 业务逻辑代码 ...
- CentOS 6.4 + 曙光DS200 IPSan组建FTP服务器
CentOS 6.4 + 曙光DS200 IPSan组建FTP服务器 http://write.blog.csdn.net/postedit/10911105#本系列文章由ex_net(张建波)编写, ...
- 零积分下载,2014年辛星mysql教程秋季版第一本已经完工,期待您的支持
经过一段时间的不懈努力.终于,2014年辛星mysql教程秋季版的第一本,即夯实基础已经完工,在csdn的下载地址为:去下载地址 ,假设左边地址跪了,能够去http://download.csdn.n ...
- Windows Azure使用VS 2010的云应用开发过程
原文 Windows Azure使用VS 2010的云应用开发过程 作为技术人员,如果在2010还不知道云计算,那么你已经“OUT”了:作为Visual Studio平台的使用者,如果你不知道VS 2 ...
- CodeForce 439C Devu and Partitioning of the Array(模拟)
Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes ...
- Python 学习入门(21)—— 线程
本文介绍了Python对于线程的支持,包括“学会”多线程编程需要掌握的基础以及Python两个线程标准库的完整介绍及使用示例. 1. 线程基础 1.1. 线程状态 线程有5种状态,状态转换的过程如下图 ...
- 有关java中的final关键字
在java中,可能使用到final关键字修饰的有数据.方法和类. 一.final 修饰数据 有final修饰的数据是用来告诉编译器一块数据是恒定不变的,有时数据恒定不变是很有用的,比如: 1.一个永不 ...