delphi webservice服务端开发
<p>delphi webservice服务端开发</p><p>1)引用单元</p>
<p>ueses<br> Web.WebReq,<br> IdHTTPWebBrokerBridge;</p>
<p>2)WebModuleUnit1单元,DELPHI WEBSERVICE向导自动生成的</p>
<p>if Web.WebReq.WebRequestHandler <> nil then<br> Web.WebReq.WebRequestHandler.WebModuleClass := WebModuleUnit1.WebModuleClass;</p>
<p>3)创建indy通讯</p>
<p>var FServer: TIdHTTPWebBrokerBridge;<br>FServer := TIdHTTPWebBrokerBridge.Create(Self);<br>FServer.DefaultPort := port;<br>FServer.Bindings.Clear;<br>FServer.Active := True;</p>
<p>4)接口声明单元,DELPHI WEBSERVICE向导自动生成的。</p>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:true;">unit WebservicesIntf;
interface
uses Soap.InvokeRegistry, System.Types;
type
TGoods = class(TRemotable)
private
FGoodsId: String;
FGoodsName: String;
published
property GoodId: String read FGoodsId write FGoodsId;
property GoodName: String read FGoodsName write FGoodsName;
end;
TGoodsArray = array of TGoods;
TClass1 = class(TRemotable)
private
FId: String;
FName: UnicodeString;
published
property Id: String read FId write FId;
property Name: String read FName write FName;
end;
TClass1Array = array of TClass1;
{ Invokable interfaces must derive from IInvokable }
IynServices = interface(IInvokable)
['{91ACA512-4204-4FAF-A26D-05E265BEAA72}']
{ Methods of Invokable interface must not use the default }
{ calling convention; stdcall is recommended }
function getClass1Array: TClass1Array; stdcall;
function saveClass1Array(value: TClass1Array): Boolean; stdcall;
function GetGoodsArray(AAccountNo, ASQL: string): TGoodsArray; stdcall;
function GetGoods(AAccountNo, ASQL: string): string; stdcall;
end;
implementation
initialization
{ Invokable interfaces must be registered }
InvRegistry.RegisterInterface(TypeInfo(IynServices));
end.
</pre>
</div>
<p> 5)接口实现单元,DELPHI WEBSERVICE向导自动生成的</p>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:true;">{ Invokable implementation File for TTest which implements ITest }
unit WebservicesImpl;
interface
uses
ynJsonSerial, System.SysUtils, uUnidacPool, uUnidac, uLog, Soap.InvokeRegistry,
System.Types, WebservicesIntf;
type
{ TynServices }
TynServices = class(TInvokableClass, IynServices)
public
function getClass1Array: TClass1Array; stdcall;
function saveClass1Array(value: TClass1Array): Boolean; stdcall;
function GetGoodsArray(AAccountNo, ASQL: string): TGoodsArray; stdcall;
function GetGoods(AAccountNo, ASQL: string): string; stdcall;
end;
implementation
{ TynServices }
function TynServices.getClass1Array: TClass1Array;
begin
SetLength(Result, 2);
Result := TClass1.Create;
Result.Id := '编号1';
Result.Name := '名称1';
Result := TClass1.Create;
Result.Id := '编号2';
Result.Name := '名称2';
end;
function TynServices.GetGoods(AAccountNo, ASQL: string): string;
begin
var pool: TUnidacPool := GetDBPool(AAccountNo);
var js: TynJsonCross := TynJsonCross.Create;
var dm: TUnidac := pool.Lock;
try
try
dm.qry.Close;
dm.qry.SQL.Clear;
dm.qry.SQL.Add(ASQL);
dm.qry.Open;
Result := js.DataSetToJson(dm.qry);
except
on E: Exception do
Log.WriteLog('TynServices.GetGoods ' + E.Message);
end;
finally
js.Free;
pool.Unlock(dm);
end;
end;
function TynServices.GetGoodsArray(AAccountNo, ASQL: string): TGoodsArray;
//var
//dbpool: TDBPool;
//firedac: TynFiredac;
begin
//dbpool := GetDBPool(AAccountNo);
//firedac := dbpool.Lock;
//try
// try
// firedac.FDQuery1.Close;
// firedac.FDQuery1.SQL.Clear;
// firedac.FDQuery1.SQL.Add(ASQL);
// firedac.FDQuery1.Open;
// SetLength(Result, firedac.FDQuery1.RecordCount);
// firedac.FDQuery1.First;
// while not firedac.FDQuery1.Eof do
// begin
// Result.GoodId := firedac.FDQuery1.FieldByName('goodsid').AsString;
// Result.GoodName := firedac.FDQuery1.FieldByName('goodsname').AsString;
// firedac.FDQuery1.Next;
// end;
// except
// on E: Exception do
// begin
// Log.WriteLog('TynServices.GetGoodsArray ' + E.Message);
// end;
// end;
//finally
// firedac.FDQuery1.Close;
// firedac.FDConnection1.Close;
// dbpool.Unlock(firedac);
//end;
end;
function TynServices.saveClass1Array(value: TClass1Array): Boolean;
begin
Result := False;
end;
initialization
{ Invokable classes must be registered }
InvRegistry.RegisterInvokableClass(TynServices);
end.
</pre>
</div>
<p> </p>
<p> </p>
</div>
<div id="MySignature" role="contentinfo">
<p>本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/12653005.html</p><br><br>
来源:https://www.cnblogs.com/hnxxcxg/p/12653005.html
頁:
[1]