一般http访问的地址是

http://localhost:8099/datasnap/rest/TServerMethods1/EchoString/abc

一、用FDConnection1连接Datasnap服务器

FireDAC  连接Datasnap服务端。这个是tcp协议连接通讯,长连接。服务端不是没个方法都建立实例释放实例,而是连接的时候建立,中间调用多少个方法都不释放实例,连接断开才释放。

不是。net的web api或者Datasnap 的 webmodule,纯粹是tcp。

DriverID=DS
Protocol=tcp/ip
Server=127.0.0.1
Port=
User_Name=dsusr
Password=

http://docwiki.embarcadero.com/RADStudio/Berlin/en/Connect_to_DataSnap_Server_(FireDAC)

fdstoreproc 执行返回数据
FDStoredProc1.Close;
FDStoredProc1.Unprepare;
FDStoredProc1.StoredProcName := 'TServerMethods1.QueryData';
FDStoredProc1.Prepare;
FDStoredProc1.ParamByName('sql').Value := 'select * from MyTable';
FDStoredProc1.open;
FDMemTable1.Close;
FDMemTable1.Data := FDStoredProc1.Data;

如果是字符串参数及返回字符串参数

FDStoredProc1.Params.Items[0].Value := 'hello'; //入参
  Self.Caption := FDStoredProc1.Params.Items[1].Value; //返回参数

也可以通过ParamByName对Datasnap server的方法传参,是不是很方便?

FDStoredProc1.Params.ParamByName('value').Value:= 'hello';
  FDStoredProc1.Params.ParamByName('retvlue').Value;

self.Caption:=  FDStoredProc1.Params.Items[0].Name;
self.Caption:=      FDStoredProc1.Params.Items[1].Name;

procedure TDepartmentsClientForm.Button3Click(Sender: TObject);
begin
FDStoredProc1.Close;
FDStoredProc1.Unprepare;
FDStoredProc1.StoredProcName := 'TServerMethods1.ReverseString';
FDStoredProc1.Prepare;
FDStoredProc1.Params.Items[].Value := 'hello';
FDStoredProc1.Params.Count;
FDStoredProc1.ExecProc;
Self.Caption := FDStoredProc1.Params.Items[].Value; end; procedure TDepartmentsClientForm.Button4Click(Sender: TObject);
begin FDStoredProc1.Close;
FDStoredProc1.Unprepare;
FDStoredProc1.StoredProcName := 'TServerMethods1.EchoString';
FDStoredProc1.Prepare;
FDStoredProc1.Params.Items[].Value := 'hello';
FDStoredProc1.Params.Count;
FDStoredProc1.ExecProc;
Self.Caption := FDStoredProc1.Params.Items[].Value; end;

二、TSQLConnection,(该控件其实也支持android平台)

参考官方的例子

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

也支持http。

D:\Users\Public\Documents\Embarcadero\Studio\14.0\Samples\CPP\DataSnap\SimpleDataSnapDemo\CppDataSnapClient\CppDataSnapClientApp.cbproj

 这个也是tcp通讯,原理同上。

SQLConnection控件,Params,

DriverName=DataSnap

HostName=localhost

port=211

void __fastcall TForm2::CheckBox1Change(TObject *Sender)
{
SQLConnection1->Connected = CheckBox1->IsChecked;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
TServerMethods1Client *Temp;
Temp = new TServerMethods1Client(SQLConnection1->DBXConnection);
try {
Label1->Text = Temp->EchoString(Edit1->Text);
}
__finally {
delete Temp;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button2Click(TObject *Sender)
{
TServerMethods1Client *Temp;
Temp = new TServerMethods1Client(SQLConnection1->DBXConnection);
try {
Label1->Text = Temp->ReverseString(Edit1->Text);
}
__finally {
delete Temp;
}
}
DataSnapClientClasses.h
#ifndef DataSnapClientClassesH
#define DataSnapClientClassesH #include "DBXCommon.hpp"
#include "Classes.hpp"
#include "SysUtils.hpp"
#include "DB.hpp"
#include "SqlExpr.hpp"
#include "DBXDBReaders.hpp"
#include "DBXCDSReaders.hpp" class TServerMethods1Client : public TObject
{
private:
TDBXConnection *FDBXConnection;
bool FInstanceOwner;
TDBXCommand *FEchoStringCommand;
TDBXCommand *FReverseStringCommand;
public:
__fastcall TServerMethods1Client(TDBXConnection *ADBXConnection);
__fastcall TServerMethods1Client(TDBXConnection *ADBXConnection, bool AInstanceOwner);
__fastcall ~TServerMethods1Client();
System::UnicodeString __fastcall EchoString(System::UnicodeString value);
System::UnicodeString __fastcall 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. //---------------------------------------------------------------------------
//
// Created by the DataSnap proxy generator.
// 1/31/2013 2:39:56 PM
// #include "DataSnapClientClasses.h" System::UnicodeString __fastcall TServerMethods1Client::EchoString(System::UnicodeString value)
{
if (FEchoStringCommand == NULL)
{
FEchoStringCommand = FDBXConnection->CreateCommand();
FEchoStringCommand->CommandType = TDBXCommandTypes_DSServerMethod;
FEchoStringCommand->Text = "TServerMethods1.EchoString";
FEchoStringCommand->Prepare();
}
FEchoStringCommand->Parameters->Parameter[]->Value->SetWideString(value);
FEchoStringCommand->ExecuteUpdate();
System::UnicodeString result = FEchoStringCommand->Parameters->Parameter[]->Value->GetWideString();
return result;
} System::UnicodeString __fastcall TServerMethods1Client::ReverseString(System::UnicodeString value)
{
if (FReverseStringCommand == NULL)
{
FReverseStringCommand = FDBXConnection->CreateCommand();
FReverseStringCommand->CommandType = TDBXCommandTypes_DSServerMethod;
FReverseStringCommand->Text = "TServerMethods1.ReverseString";
FReverseStringCommand->Prepare();
}
FReverseStringCommand->Parameters->Parameter[]->Value->SetWideString(value);
FReverseStringCommand->ExecuteUpdate();
System::UnicodeString result = FReverseStringCommand->Parameters->Parameter[]->Value->GetWideString();
return result;
} __fastcall TServerMethods1Client::TServerMethods1Client(TDBXConnection *ADBXConnection)
{
if (ADBXConnection == NULL)
throw EInvalidOperation("Connection cannot be nil. Make sure the connection has been opened.");
FDBXConnection = ADBXConnection;
FInstanceOwner = True;
} __fastcall TServerMethods1Client::TServerMethods1Client(TDBXConnection *ADBXConnection, bool AInstanceOwner)
{
if (ADBXConnection == NULL)
throw EInvalidOperation("Connection cannot be nil. Make sure the connection has been opened.");
FDBXConnection = ADBXConnection;
FInstanceOwner = AInstanceOwner;
} __fastcall TServerMethods1Client::~TServerMethods1Client()
{
delete FEchoStringCommand;
delete FReverseStringCommand;
}

 三、DSRestConnection

这个是http调用,rest风格,每一次方法的调用都是一次实例化,方法,释放的3个过程。

就是 web api/rest风格,调用方法类似SQLConnection,生个各个方法的定义。

只支持http和https两种通讯协议。调用datasnap Rest服务。

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

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

self.DSRestConnection1.Host:='127.0.0.1';
self.DSRestConnection1.Port:= ;
self.DSRestConnection1.Protocol:=''//http https TServerMethods1Client这个生成很多方法
ClientModule2.ServerMethods1Client.GetDepartmentNames();
function TServerMethods1Client.GetDepartmentNames(const ARequestFilter: string): TFDJSONDataSets;
begin
if FGetDepartmentNamesCommand = nil then
begin
FGetDepartmentNamesCommand := FConnection.CreateCommand;
FGetDepartmentNamesCommand.RequestType := 'GET';
FGetDepartmentNamesCommand.Text := 'TServerMethods1.GetDepartmentNames';
FGetDepartmentNamesCommand.Prepare(TServerMethods1_GetDepartmentNames);
end;
FGetDepartmentNamesCommand.Execute(ARequestFilter);
if not FGetDepartmentNamesCommand.Parameters[].Value.IsNull then
begin
FUnMarshal := TDSRestCommand(FGetDepartmentNamesCommand.Parameters[].ConnectionHandler).GetJSONUnMarshaler;
try
Result := TFDJSONDataSets(FUnMarshal.UnMarshal(FGetDepartmentNamesCommand.Parameters[].Value.GetJSONValue(True)));
if FInstanceOwner then
FGetDepartmentNamesCommand.FreeOnExecute(Result);
finally
FreeAndNil(FUnMarshal)
end
end
else
Result := nil;
end;

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

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

也就是客户端调用,是通过生成服务方法代理

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

Generating DataSnap Server Method Proxies

Go Up to DataSnap Server Application

Proxy DataSnap classes are needed in client applications to invoke server methods. In order to generate server methods, drop a TDSRestConnection in a form and connect to a running DataSnap server in design mode. Right-click the TDSRestConnection component and select Generate DataSnap Client Classes.
The proxy unit is added to the current project and each exposed method
can be used to invoke the corresponding server method. When generating a
Delphi proxy for the server, that proxy should have on it the useful DSAdmin methods. These DSAdmin
methods are any functions or procedures publicly declared and exposed
to the user, as well as any visible methods in the classes that DSAdmin extends.

If the server method signature changes or methods are added or removed, the same option will refresh the proxy unit.

后续参考http://blog.csdn.net/cb168/article/details/14454499 客户端部分

客户端如何连接 DataSnap Server 调用服务的方法的更多相关文章

  1. ems lite 客户端远程连接mysql server

    在本地用ems客户端远程连接虚拟机上的mysql server,弹出客户端没有权限访问mysql server.使用下面方法进行设置:mysql> select host,user,passwo ...

  2. [android] 代码注册广播接收者&利用广播调用服务的方法

    利用广播调用服务里面的方法,间接的方式调用服务内部的方法,与现实中差不多,请媒体曝光 主界面里面 在界面创建的时候开启一下服务普通的startService()方法 发送一条广播出去 获取Intent ...

  3. 不同网段无法加载ArcGIS Server发布服务解决方法

    问题描述: ArcGIS Server 10发布的服务, (1)在相同网段的Desktop9.3和Engine 9.3程序下可以正常显示, (2)在不同网段Desktop9.3和Engine 9.3程 ...

  4. 绑定方式开始服务&调用服务的方法

    1.编写activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...

  5. Android--绑定服务调用服务的方法

    Service依照其启动的方式,可分为两种: 1.Started Started的Service.通过在Application里用startService(Intent intent)方法来启动.这样 ...

  6. Android -- service 利用广播调用服务的方法

    1. 实现原理,在Service里面注册一个广播接收者, 想要调用的时候app发送出广播, 后台的service里面的广播接收者接收到广播,并调用service里面的方法. 2. 示例代码 MainA ...

  7. cxf 动态创建客户端,局域网能正常调用服务端,外网不能访问

  8. [android] 绑定方式开启服务&调用服务的方法

    需求:后台开启一个唱歌服务,这个服务里面有个方法切换歌曲 新建一个SingService继承系统Service 重写onCreate()和onDestory()方法 填一个自定义的方法changeSi ...

  9. 代码注册广播接收者&利用广播调用服务的方法服务声命周期(混合开启)

    1)说明文档: 2)效果演示: 3)代码演示:

随机推荐

  1. 弱也有弱的ACM经历

    作为一名弱校的acm渣渣,在经历了三年的acm生涯后,现在终于要毕业了,最后也来总结下自己在这几年中做acm的经历与感受.以下是参赛总结: 2013年: ACM/ICPC长沙邀请赛(打铁=_=) AC ...

  2. day10 python学习 函数的嵌套命名空间作用域 三元运算 位置参数 默认参数 动态参数

    1.三元运算 #1.三元运算 利用已下方法就可以实现一步运算返回a b中大的值 def my_max(a,b): c=0 a=int(input('请输入')) b=int(input('请输入')) ...

  3. yugabyte 集成JanusGraph测试

    yugabyte 集成图数据库JanusGraph,原理比较简单就是yugabyte 内置Cassandra,配置好JanusGraph 的访问就可以了. 使用docker 模式部署 创建yugaby ...

  4. dgraph 基本查询语法 一

    dgraph 的查询语法是在graphql 上的扩展,添加了新的支持,同时官方提供了一个 学习的网站 https://tour.dgraph.io/ 基本环境(cluster 模式的) 参考 gith ...

  5. apache隐藏web服务器的版本信息

    curl -I yourdomain.com 能看到什么? Server: Apache xxx PHP xxx XXX xxx 我们不妨看看 curl -I www.google.com 结果如何: ...

  6. PHP mongodb 的使用

    mongodb 不用过多的介绍了,NOSQL的一种,是一个面向文档的数据库,以其方便灵活的数据结构,对于开发者来说是比较友好的,同时查询的速度也是比较快的,现在好多网站 开始使用mongodb ,具体 ...

  7. C语言利用SMTP协议发送邮件

    #ifdef WIN32 #include <windows.h> #include <stdio.h> #else #include <stdio.h> #inc ...

  8. JS判断IP的正则表达式

    <html> <head> <title>最简洁的IP判断正则表达式</title> <meta http-equiv="Content ...

  9. 【python】class之super关键字的作用

    在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如代码段1: 代码段1: class A: def __init__(self):    prin ...

  10. 【jmeter】jmeter环境搭建

    一. 工具描述 apache jmeter是100%的java桌面应用程序,它被设计用来加载被测试软件功能特性.度量被测试软件的性能.设计jmeter的初衷是测试web应用,后来又扩充了其它的功能.j ...