DelphiXE7中创建WebService(服务端+客户端)
相关资料:
http://www.2ccc.com/news/Html/?1507.html
http://www.dfwlt.com/forum.php?mod=viewthread&tid=922
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
服务端-实例代码:
unit WebModuleUnit1; interface uses System.SysUtils, System.Classes, Web.HTTPApp, Soap.InvokeRegistry,
Soap.WSDLIntf, System.TypInfo, Soap.WebServExp, Soap.WSDLBind, Xml.XMLSchema,
Soap.WSDLPub, Soap.SOAPPasInv, Soap.SOAPHTTPPasInv, Soap.SOAPHTTPDisp,
Soap.WebBrokerSOAP, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MSAcc,
FireDAC.Phys.MSAccDef, FireDAC.Phys.MSSQLDef, FireDAC.Stan.Param,
FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, Datasnap.DBClient,
Datasnap.Provider, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
FireDAC.Phys.ODBCBase, FireDAC.Phys.MSSQL; type
TWebModule1 = class(TWebModule)
HTTPSoapDispatcher1: THTTPSoapDispatcher;
HTTPSoapPascalInvoker1: THTTPSoapPascalInvoker;
WSDLHTMLPublish1: TWSDLHTMLPublish;
FDConnection1: TFDConnection;
FDPhysMSSQLDriverLink1: TFDPhysMSSQLDriverLink;
FDQuery1: TFDQuery;
DataSetProvider1: TDataSetProvider;
ClientDataSet1: TClientDataSet;
procedure WebModule1DefaultHandlerAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
private
{ Private declarations }
public
function GetInfo: widestring;
function SetSQL(ASQL: widestring): widestring;
{ Public declarations }
end; var
WebModuleClass: TComponentClass = TWebModule1; implementation {%CLASSGROUP 'Vcl.Controls.TControl'} {$R *.dfm} function TWebModule1.GetInfo: widestring;
begin
ClientDataSet1.Close;
ClientDataSet1.Open;
Result := ClientDataSet1.XMLData;
ClientDataSet1.Close;
end; function TWebModule1.SetSQL(ASQL: widestring): widestring;
begin
FDQuery1.Close;
FDQuery1.SQL.Text := ASQL;
try
FDQuery1.ExecSQL;
Result := '成功 ';
except
Result := '失败';
end;
end; procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
WSDLHTMLPublish1.ServiceInfo(Sender, Request, Response, Handled);
end; end.
{ Invokable interface IMyData }
unit MyDataIntf;
interface
uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns;
type
{ Invokable interfaces must derive from IInvokable }
IMyData = interface(IInvokable)
['{865DBF5C-8DE1-4D01-AE04-16D04A3F5EF0}']
function GetInfo:widestring;stdcall;
function SetSQL(ASQL: widestring): widestring;stdcall;
{ Methods of Invokable interface must not use the default }
{ calling convention; stdcall is recommended }
end;
implementation
initialization
{ Invokable interfaces must be registered }
InvRegistry.RegisterInterface(TypeInfo(IMyData));
end.
{ Invokable implementation File for TMyData which implements IMyData }
unit MyDataImpl;
interface
uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns, MyDataIntf;
type
{ TMyData }
TMyData = class(TInvokableClass, IMyData)
public
function GetInfo:widestring;stdcall;
function SetSQL(ASQL: widestring): widestring;stdcall;
end;
implementation
uses WebModuleUnit1;
{ TMyData }
function TMyData.GetInfo: widestring;
var
oDM: TWebModule1;
begin
oDM := TWebModule1.Create(nil);
result := oDM.GetInfo;
oDM.Free;
end;
function TMyData.SetSQL(ASQL: widestring): widestring;
var
oDM: TWebModule1;
begin
oDM := TWebModule1.Create(nil);
result := oDM.SetSQL(ASQL);
oDM.Free;
end;
initialization
{ Invokable classes must be registered }
InvRegistry.RegisterInvokableClass(TMyData);
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
客户端-实例代码:
unit Unit1; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.DBGrids, Data.DB,
Datasnap.DBClient, Vcl.StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation
uses IMyData1;
{$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var
ows: IMyData;
s: string;
begin
ows := GetIMyData(true,'http://localhost:8080/wsdl/IMyData',nil); //参数中可以使用配置的url
s := ows.GetInfo;
if length(s) <> then
ClientDataSet1.xmldata := s;
end; procedure TForm1.Button2Click(Sender: TObject);
var
ows:IMyData;
s:string;
begin
ows := GetIMyData(true,'http://localhost:8080/wsdl/IMyData',nil); //参数中可以使用配置的url
s := ows.SetSQL('delete from usesr where yonghu=' + QuotedStr('ni2'));
if length(s) <> then
Edit1.Text := s;
end; end.
DelphiXE7中创建WebService(服务端+客户端)的更多相关文章
- DelphiXE7中创建WebService(服务端+客户端) good
相关资料:http://www.2ccc.com/news/Html/?1507.html DelphiXE7新建WebService具体操作:1.打开“DelphiXE7”->“File”-& ...
- 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提供数据支持,看了网上相关大片的资料也 ...
随机推荐
- web rest api tools
https://chrome.google.com/webstore/search/postman-REST%20Client
- 运行Android应用时提示ADB是否存在于指定路径问题
打开eclipse,选择指定的Android应用工程并Run,提示: [2014-06-28 11:32:26 - LinearLayout] The connectionto adb is down ...
- zlib代码生成
1.主页下载zlib-1.2.8的source code的压缩包:F:\Develop Tools\zlib-1.2.8 2.下载安装cmake-2.8.1-win32-x86 3.用cmake生成z ...
- hdu 2986 Ballot evaluation (模拟)
题目 上次比赛的题目,好长时间了. 这几天感冒了很难受, 直到现在才整理, 上次比赛的时候,出了各种错误, ,,,样例都没过,题目读的也很差,今天做的时候, 看了一下网上的,发现一个代码特别简洁, ...
- Codeforces 379D - New Year Letter
原题地址:http://codeforces.com/contest/379/problem/D 题目大意:给出一种生成字符串的方法 s[k] = s[k - 2] + s[k - 1],其中加法意为 ...
- LinQ综合应用实例
直接上代码,内容很浅显易懂,在这里就不做更多的解释,解释见代码注释. using System; using System.Collections.Generic; using System.Linq ...
- eclipse启动出现“An Error has Occurred. See the log file”解决方法
最近在启动eclipse时出现了“An Error has Occurred. See the log file”的错误,点击确定后也不能启动eclipse.查看log文件,出现类似: java.la ...
- [Sciter系列] MFC下的Sciter–3.Sciter脚本与底层交互
[Sciter系列] MFC下的Sciter–3.Sciter脚本与底层交互,脚本调用底层自定义的方法函数. 本系列文章的目的就是一步步构建出一个功能可用,接口基本完善的基于MFC框架的SciterF ...
- 【 D3.js 高级系列 】 总结
高级系列的教程已经完结,特此总结. 月初的时候曾说过本月内完结高级教程,今天是最后一天,算是可以交差了.O(∩_∩)O~ 如此一来,[入门]-[进阶]-[高级]三个系列的教程算是完成了.本教程的目的在 ...
- LeetCode: Word Break I && II
I title: https://leetcode.com/problems/word-break/ Given a string s and a dictionary of words dict, ...