博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
创建DataSnap Server
阅读量:7071 次
发布时间:2019-06-28

本文共 7129 字,大约阅读时间需要 23 分钟。

DataSnap REST Application

http://edn.embarcadero.com/article/41305

 

2017.1.19 官方例子

https://community.embarcadero.com/blogs/entry/in-the-c-builder-of-rad-server-firedac-sqlserver-connection

 

官方创建datasnapServer的步骤说明

 http://docwiki.embarcadero.com/RADStudio/Tokyo/en/DataSnap_Server_Wizard_for_Windows

 

这个是创建 Datasnap Rest 服务的步骤。

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/DataSnap_REST_Application_Wizard_for_Windows 

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Tutorial:_Using_a_REST_DataSnap_Server_with_an_Application

 http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Tutorial:_Using_a_REST_DataSnap_Server_with_an_Application_and_FireDAC

 

建立DataSnap/REST服务器,请点选Files|New菜单,在DataSnap Server选项中选择DataSnap Server图像,如下图所示:3个选项都可以选择,创建后都是DataSnap服务器

官方例子参考D:\Users\Public\Documents\Embarcadero\Studio\14.0\Samples\CPP\DataSnap\SimpleDataSnapDemo\CppDataSnapServer\CppDataSnapServerApp.cbproj

注意:TDSTCPServerTransport.poolsize 线程池

TDSTCPServerTransport.maxThreads  并发连接数量

TDSServerClass.LIFECycle,  SESSION/SERVER/INVOCATION

Representational State Transfer (REST) is a new architecture for Web Services that is having a significant impact on the industry

ServerMethodsUnit1.cpp 

DSServerModuleCreate是每个客户端连接的时候触发,两个客户端连接就触发两次,所以用到全局指针的话,第二次的触发就可能影响了第一次的指针,必须注意特别小心。

关于数据库操作必须写到ServerMethodsUnit1,包括数据库连接,ServerMethodsUnit1具有线程功能, 一个客户端连接一个线程实例,一个实例就是new一个ServerMethodsUnit1类,各个互不影响。

普通的datamodule无线程功能。

 

视频教程

 http://www.embarcadero.com/rad-in-action/datasnap

 

服务器可以创建exe,app,也可以是服务;可以是windows 平台,也可以是firemonkey跨平台。

 

一路完成后会生成控件

TDSServer,TDSTCPServerTransport以及TDSServerClass、TDSHTTPService

 

USEFORM("MainForm.cpp", Form1);USEFORM("ServerContainerUnit1.cpp", ServerContainer1); /* TDataModule: File Type *///---------------------------------------------------------------------------int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int){    try    {        Application->Initialize();        Application->MainFormOnTaskBar = true;        Application->CreateForm(__classid(TForm1), &Form1);        Application->CreateForm(__classid(TServerContainer1), &ServerContainer1);        Application->Run();    }}//----------------------------------------------------------------------------#ifndef ServerMethodsUnit1H#define ServerMethodsUnit1H//----------------------------------------------------------------------------#include 
#include
//----------------------------------------------------------------------------class DECLSPEC_DRTTI TServerMethods1 : public TComponent{private: // User declarationspublic: // User declarations System::UnicodeString EchoString(System::UnicodeString value); System::UnicodeString ReverseString(System::UnicodeString value);};#endif//---------------------------------------------------------------------------// This software is Copyright (c) 2014 Embarcadero Technologies, Inc. // You may only use this software if you are an authorized licensee// of an Embarcadero developer tools product.// This software is considered a Redistributable as defined under// the software license agreement that comes with the Embarcadero Products// and is subject to that software license agreement.//---------------------------------------------------------------------------//----------------------------------------------------------------------------#include
#pragma hdrstop#include "ServerMethodsUnit1.h"#include
//----------------------------------------------------------------------------#pragma package(smart_init)//----------------------------------------------------------------------------System::UnicodeString TServerMethods1::EchoString(System::UnicodeString value){ return value;}//----------------------------------------------------------------------------System::UnicodeString TServerMethods1::ReverseString(System::UnicodeString value){ return ::ReverseString(value);}//----------------------------------------------------------------------------

 

//----------------------------------------------------------------------------#ifndef ServerContainerUnit1H#define ServerContainerUnit1H//---------------------------------------------------------------------------#include 
#include
#include
#include
#include
#include
//----------------------------------------------------------------------------class TServerContainer1 : public TDataModule{__published: // IDE-managed Components TDSServer *DSServer1; TDSTCPServerTransport *DSTCPServerTransport1; TDSServerClass *DSServerClass1; void __fastcall DSServerClass1GetClass(TDSServerClass *DSServerClass, TPersistentClass &PersistentClass);private: // User declarationspublic: // User declarations __fastcall TServerContainer1(TComponent* Owner);};//----------------------------------------------------------------------------extern PACKAGE TServerContainer1 *ServerContainer1;//----------------------------------------------------------------------------#endif//---------------------------------------------------------------------------// This software is Copyright (c) 2014 Embarcadero Technologies, Inc. // You may only use this software if you are an authorized licensee// of an Embarcadero developer tools product.// This software is considered a Redistributable as defined under// the software license agreement that comes with the Embarcadero Products// and is subject to that software license agreement.//---------------------------------------------------------------------------//----------------------------------------------------------------------------#include
#pragma hdrstop#include
#include
#include
#include "ServerMethodsUnit1.h"#include "ServerContainerUnit1.h"//---------------------------------------------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TServerContainer1 *ServerContainer1;//---------------------------------------------------------------------------__fastcall TServerContainer1::TServerContainer1(TComponent* Owner) : TDataModule(Owner){}//----------------------------------------------------------------------------void __fastcall TServerContainer1::DSServerClass1GetClass(TDSServerClass *DSServerClass, TPersistentClass &PersistentClass){ PersistentClass = __classid(TServerMethods1);}//----------------------------------------------------------------------------//---------------------------------------------------------------------------

 

多个类文件

ServerMethodsUnit1.cpp文件中就是类 class TServerMethods1 : public TDSServerModule,如果想多个类,例如分模块分业务多个类,File>new>Other>DataSnap Server》选择 Server Module新添加一个类。没有打开任何功能时Server Module是不可见的。只有打开了某个应用服务器的工程,再new的时候才能看见!

 https://newsgroups.embarcadero.com/thread.jspa?threadID=229169

https://forums.embarcadero.com/thread.jspa?messageID=833882

ServerMethodsUnit1、ServerMethodsUnit2

DSServerClass1、DSServerClass2

procedure TWebModule1.DSServerClass2GetClass(DSServerClass: TDSServerClass;  var PersistentClass: TPersistentClass);begin PersistentClass := ServerMethodsUnit2.TDSServerModule2;end;

这样就注册上第二个单位类,多模块,多个类、多个业务、多个接口、分离

转载地址:http://ijkml.baihongyu.com/

你可能感兴趣的文章
jquery widgets 弹框
查看>>
Linux系统管理命令之权限管理
查看>>
取汉子拼音首字母的VB.Net方法
查看>>
使用Maven对JAVA程序打包-带主类、带依赖【转】
查看>>
[CSS] 点击事件触发的动画
查看>>
飞鱼星路由器配置端口映射
查看>>
《Linux Device Drivers》第十八章 TTY驱动程序——note
查看>>
virtual的使用方法
查看>>
POJ 1321 棋盘问题(DFS板子题,简单搜索练习)
查看>>
POJ 3155 Hard Life(最大密度子图)
查看>>
剑英的区块链学习手记(二)
查看>>
.Net接口调试与案例
查看>>
SQL Server 中BIT类型字段增删查改那点事
查看>>
【Java集合源代码剖析】TreeMap源代码剖析
查看>>
【算法】 算法和数据结构绪论
查看>>
LeetCode OJ 之 Ugly Number II (丑数-二)
查看>>
(一)Thymeleaf用法——Thymeleaf简介
查看>>
【Python】 命名空间与LEGB规则
查看>>
巴斯卡三角形
查看>>
产品和团队
查看>>