当前位置: 首页 > 编程日记 > 正文

delphi xe 文件服务器,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.相关资料:http://www.2ccc.com/news/Html/?1507.html DelphiXE7新建WebService具体操作:1.打开“DelphiXE7”->“File”-& ...

相关文章:

Android app 别用中文名

/************************************************************************** Android app 别用中文名* 说明&#xff1a;* 本来想分析一下这份源代码&#xff0c;结果发现因为项目名中有中文不能自动生成R* 文件&#xff0c;于是不想分析了。** …

一线互联网常见的14个Java面试题,你颤抖了吗程序员

跳槽不算频繁&#xff0c;但参加过不少面试&#xff08;电话面试、face to face面试&#xff09;&#xff0c;面过大/小公司、互联网/传统软件公司&#xff0c;面糊过&#xff08;眼高手低&#xff0c;缺乏实战经验&#xff0c;挂掉&#xff09;&#xff0c;也面过人&#xff0…

复化梯形公式,Newton-Cotes公式,变量代换后的复化梯形公式,Gauss-Legendre公式,Gauss-Jacobi公式插值积分的精确度比较

1.问题 分别计算积分 Ic∫01cos⁡xxdx1.809048475800...I_c\int_0^1\frac{\cos{x}}{\sqrt{x}}dx1.809048475800... Ic​∫01​x​cosx​dx1.809048475800... Is∫01sin⁡xxdx0.620536603446I_s\int_0^1\frac{\sin{x}}{\sqrt{x}}dx0.620536603446 Is​∫01​x​sinx​dx0.62053…

Elasticsearch 知识点目录

2019独角兽企业重金招聘Python工程师标准>>> 经过一段时间的编写&#xff0c;完成了第一个版本的Elasticsearch书籍的编写&#xff0c;目录结构如下&#xff1a; 1 Elasticsearch入门 7 1.1 Elasticsearch是什么 7 1.1.1 Elasticsearch是什么 7 1.1.2 Elasticsearch…

不要千言万语,一组漫画让你秒懂最终一致性

直接上图 如果你以前看过最终一致性的定义那么你一定会为这幅精彩漫画拍手叫好。 你要是不知道什么是最终一致性你可以看看下面的权威定义&#xff0c;当然了网上关于什么是最终一致性的帖子铺天盖地&#xff0c;也许你已经很明白了&#xff0c;即使这样你是不是依然为此图欢呼…

Feign实现服务调用

上一篇博客我们使用ribbonrestTemplate实现负载均衡调用服务&#xff0c;接下来我们使用feign实现服务的调用&#xff0c;首先feign和ribbon的区别是什么呢&#xff1f; ribbon根据特定算法,从服务列表中选取一个要访问的服务; RoundRobinRule:轮询RandomRule:随机Availability…

度量,跟踪和日志记录

今天&#xff0c;我有幸参加了2017年的分布式追踪峰会&#xff0c;其中有很多来自AWS / X-Ray&#xff0c;OpenZipkin&#xff0c;OpenTracing&#xff0c;Instana&#xff0c;Datadog&#xff0c;Librato等公司的人员&#xff0c;我很遗憾我忘记了这一点。有一次讨论转向了项目…

python 第六章 函数 pta(1)

1.Multiple-Choice 1.print(type(lambda:3))的输出结果是____。 A.<class ‘function’> B.<class ‘int’> C.<class ‘NoneType’> D.<class ‘float’> 答案&#xff1a;A 2.在Python中&#xff0c;对于函数定义代码的理解&#xff0c;正确的理解…

生成.a文件步骤

1.新建一个Project 选择 iOS->Framework & Library ->Cocoa Touch Static Library点击Next-> 输入Product Name 2.删除自动生成的文件 替换成我们需要的文件 如&#xff1a;原本自定生成的文件为继承自NSObject的&#xff0c;而你需要的为继承自UIView的&#xff…

机器学习之优雅落地线性回归法

在统计学中&#xff0c;线性回归&#xff08;Linear regression&#xff09;是利用称为线性回归方程的最小二乘函数对一个或多个自变量和因变量之间关系进行建模的一种回归分析维基百科。简单线性回归当只有一个自变量的时候&#xff0c;成为简单线性回归。简单线性回归模型的思…

SpringBoot整合Grpc实现跨语言RPC通讯

什么是gRPC gRPC是谷歌开源的基于go语言的一个现代的开源高性能RPC框架&#xff0c;可以在任何环境中运行。它可以有效地连接数据中心内和跨数据中心的服务&#xff0c;并提供可插拔的支持&#xff0c;以实现负载平衡&#xff0c;跟踪&#xff0c;健康检查和身份验证。它还适用…

python 第六章 函数

1.函数的定义 def 名称(形参): 函数体 2.函数的调用 名称(实参) 单独文件&#xff1a;模块 调用方式——模块.名称 3.函数的参数类型 1.位置参数&#xff1a; def add(a,b):add(2,3) #顺序&#xff0c;个数&#xff0c;数据类型都要相同&#xff01;&#xff01;&#xf…

C++简单使用Jsoncpp来读取写入json文件

一、源码编译 C操作json字符串最好的库应该就是jsoncpp了&#xff0c;开源并且跨平台。它可以从这里下载。 下载后将其解压到任意目录&#xff0c;它默认提供VS2003和VS2010的工程文件&#xff0c;使用VS2010可以直接打开makefiles\msvc2010目录下的sln文件。 工程文件提供Json…

BZOJ 3420: Poi2013 Triumphal arch

二分答案 第二个人不会走回头路 那么F[i]表示在i的子树内(不包括i)所需要的额外步数 F[1]0表示mid可行 k可能为0 #include<cstdio> #include<algorithm> using namespace std; int cnt,n,mid,F[300005],last[300005]; struct node{int to,next; }e[600005]; void a…

Java泛型使用需要小心

这是源自实际开发的一个坑&#xff0c;只是被我简化了。 Set<Integer> gs null;Set gss new HashSet();gs gss;gss.add("19");System.out.println(gs);for (int i : gs) {if (i19) {System.out.println("1");}} 代码经过一些转换你如果不注意以…

证明实对称正定矩阵A的Gauss-Seidel法必定收敛(完整过程)

Solution: ​ \quad将nnn阶实对称矩阵AAA设为D−L−LTD-L-L^TD−L−LT,其中DDD是AAA的所有主对角元素构成对角矩阵&#xff0c;−L-L−L是AAA的所有主对角线以下的元素构成的严格下三角矩阵。 ​ \quad此时Gauss−SeidelGauss-SeidelGauss−Seidel法的迭代矩阵为(D−L)−1LT(…

5月中旬的一些总结

考完英语口语了&#xff0c;最大的帮助就是找到了练习的方法和思路。 周三晚上有谷歌的全球IO大会。 ******** 写吴斌老师的课程作业&#xff0c;这才发现winedt过期了。用了rept之后本来是解决问题了&#xff0c;可是一联网就又不行了。总要关上再打开。用防火墙阻断却找不到选…

项目总结10:通过反射解决springboot环境下从redis取缓存进行转换时出现ClassCastException异常问题...

通过反射解决springboot环境下从redis取缓存进行转换时出现ClassCastException异常问题 关键字 springboot热部署 ClassCastException异常 反射 redis 前言 最近项目出现一个很有意思的问题&#xff0c;用户信息(token)储存在redis中&#xff1b;在获取token&#xff0c;反序列…

Rouche Theorem(Stein复分析)

Rouche Theorem&#xff1a; \quadIffandgareholomorphicfunctionsinaregionΩcontainingacircleCanditsinterior,and∣f(z)∣≥∣g(z)∣forz∈C,fandfghavethesamenumbersofzerosinsidethecircleC.If\quad f\quad and\quad g\quad are\quad holomorphic\quad functions\quad i…

Java线上程序频繁JVM FGC问题排障与启示

线上Java程序的JVM频繁FGC&#xff0c;现象如图所示&#xff1a; 一直持续FGC 5次左右&#xff0c;每次耗时1秒多不等。 FGC的原因实际上是内存不够用&#xff0c;但是运维反映堆内存是2G&#xff0c;从运维提供的参数看也是。 内存实际上一直只用到1G以内。 这时候可以自己写…

python常用数据结构的常用操作

作为基础练习吧。列表LIST&#xff0c;元组TUPLE,集合SET&#xff0c;字符串STRING等等&#xff0c;显示&#xff0c;增删&#xff0c;合并。。。 #List shoplist [apple,mango,carrot,banana] print I have ,len(shoplist), items to purchase. print These items are: for …

h5 和native 交互那些事儿

前端菜菜一枚&#xff0c;写下关于h5 和native 交互那些事情。偏前端&#xff0c;各种理论知识&#xff0c;不在赘述。之前有各位大牛已经写过。我只写代码&#xff0c;有问题&#xff0c;下面留言/* 关于h5 和native 之间的交互 JSBridge 解决问题&#xff0c;偏向前端* 使用U…

手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫

系列教程 手把手教你写电商爬虫-第一课 找个软柿子捏捏 如果没有看过第一课的朋友&#xff0c;请先移步第一课&#xff0c;第一课讲了一些基础性的东西&#xff0c;通过软柿子"切糕王子"这个电商网站好好的练了一次手&#xff0c;相信大家都应该对写爬虫的流程有了一…

Python程序设计 第六章 函数(续

复习 1. 10进制 ⇒\Rightarrow⇒ 2进制 除2取余&#xff0c;从低位到高位存储到字符串中&#xff0c;从高位到低位def d2b(n):if n>1:d2b(n//2)print(n%2,end)d2b(4)出口&#xff1a; 条件&#xff0c;值确定 &#xff08;一&#xff09;return (二&#xff09;函数体执行结…

K8S的横向自动扩容的功能Horizontal Pod Autoscaling

K8S 作为一个集群式的管理软件&#xff0c;自动化、智能化是免不了的功能。Google 在 K8S v1.1 版本中就加入了这个 Pod 横向自动扩容的功能&#xff08;Horizontal Pod Autoscaling&#xff0c;简称 HPA&#xff09;。 HPA 与之前的 Deployment、Service 一样&#xff0c;也属…

第八周例行报告

此作业要求参见&#xff1a;https://edu.cnblogs.com/campus/nenu/2018fall/homework/2326 1、本周PSP 类型 任务 开始时间 结束时间 中断时间 Delta时间 会议 事后诸葛亮会议 11.3 14&#xff1a;12 11.3 15&#xff1a;08 0min 56min 博客 编写博客《事后诸葛…

HTTP头部信息解释分析(详细整理)

这篇文章为大家介绍了HTTP头部信息&#xff0c;中英文对比分析&#xff0c;还是比较全面的&#xff0c;若大家在使用过程中遇到不了解的&#xff0c;可以适当参考下 HTTP 头部解释 1. Accept&#xff1a;告诉WEB服务器自己接受什么介质类型&#xff0c;*/* 表示任何类型&#…

深圳杯---深圳市生活垃圾处理社会总成本分析

2017年3月18日&#xff0c;国务院向全国发布了《生活垃圾分类制度实施方案》&#xff0c;这标志着中国垃圾分类制度建设开始了一个全新阶段&#xff0c;垃圾分类已成为推进社会经济绿色发展、提升城市管理和服务水平、优化人居环境的重要举措。为了保证这一目标能够顺利实现&am…

你真的掌握了并发编程volatile synchronized么?

先看代码&#xff1a; import java.util.concurrent.atomic.AtomicInteger;/**** author xialuomantian*/ public class NewTest {static volatile int a 1;static volatile int b 1;//static int a 1;//static int b 1;public static AtomicInteger aa new AtomicInteg…

SQLSERVER存储过程基本语法使用

一、定义变量 --简单赋值 declare a int set a5 print a --使用select语句赋值 declare user1 nvarchar(50) select user1张三 print user1 declare user2 nvarchar(50) select user2 Name from ST_User where ID1 print user2 --使用update语句赋值 declare user3 nv…