0

I have made a cgi web service. The code is below:

unit MyServicesImpl;

interface

uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns, MyServicesIntf,
  Data.DB,
  Data.SqlExpr, SQLConnection1, Data.Win.ADODB;

type
  { TMyServices }
  TMyServices = class(TInvokableClass, IMyServices)
  public
    function TestFunction(): TADODataSet; stdcall;
  end;

var
  ConnString: string;
  objTADOQuery: TADOQuery;
  objTSQLDS: TDataSource;
  objDS: TADODataSet;
  objTable :TADOTable;

implementation


function TMyServices.TestFunction: TADODataSet;
var
  objTSQLConnection1: TADOConnection;
var
  conStr: string;
begin

  objTSQLConnection1 := TADOConnection.Create(nil);
  conStr := 'Provider=sqloledb;' + 'Data Source=Kays-serv64-01;' +
    'Initial Catalog=Test;' + 'User Id=sa;Password=Kays@India';
  objTSQLConnection1.ConnectionString := conStr;
  objTSQLConnection1.LoginPrompt := False;

  objTSQLConnection1.Connected := True;

  if (objTSQLConnection1.Connected) then
  begin
    objTADOQuery := TADOQuery.Create(nil);
    objTSQLDS := TDataSource.Create(nil);
    objDS:= TADODataSet.Create(nil);
    objTable:= TADOTable.Create(nil);
    objTable.TableName:='expediads';
    objTADOQuery.Connection := objTSQLConnection1;
    objTADOQuery.SQL.Text := 'select * from expediads';
    objTADOQuery.Prepared := True;
    objTADOQuery.Active := True;
    objTSQLDS.DataSet := objTADOQuery;
    objDS.DataSource:=objTSQLDS;
    Result := objDS;
  end
  else
  begin
    Result := objDS;
  end;
end;

initialization

{ Invokable classes must be registered }
InvRegistry.RegisterInvokableClass(TMyServices);

end. 

Now I am trying to consume this webservice, I have used a wsdl imported. But when I used it LIke:

Procedure TForm3.TestFunction;
var
  vMyService: IMyServices;
var
  objDataSource: TDataSource;
var
  objNewDS: IMyServices1.TADODataSet;
  var
  objTSQLConnection1: TADOConnection;
var
  conStr: string;
begin

  vMyService := GetIMyServices;
  objNewDS :=vMyService.TestFunction();
  end;

The Test function returns IMyservice1.TADODataset nad hence not compatible with Data.DB.TADODataset. Please help.

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
Akshay Jamwal
  • 23
  • 1
  • 7
  • just declare objNewDS as TADODataset – whosrdaddy Jul 31 '13 at 11:04
  • [dcc32 Error] Unit3.pas(63): E2010 Incompatible types: 'Data.Win.ADODB.TADODataSet' and 'IMyServices1.TADODataSet' I get this error when I declare it as TADODataset. – Akshay Jamwal Jul 31 '13 at 11:17
  • I am afraid that it is not possible what you are trying to do here. Don't try to send the TADODataset over but the underlying data (something like an array or so) – whosrdaddy Jul 31 '13 at 12:02
  • Okey in that case If I would need such functionality where I want to bind the data coming from webservice, what would you suggest? – Akshay Jamwal Jul 31 '13 at 12:56

1 Answers1

1

You cannot do that as the TADODataSet cannot be remoted as it would need the TADOConnection and such things like ConnectionString on the client as well as on the server.

The way to remove data using Delphi us using DataSnap with a TSoapDataModule on the server side containing a TClientDataSet which gets populated from the TADODataSet using a TDataSetProvider, and a on the client side a TSoapConnection plus TClientDataSet on the client.

DataSnap then will perform all the read/update traffic for you using SOAP (i.e. XML over HTTP).

See the DataSnap videos from Pawel Glowacki to get an idea on how to set this up, then read the documentation at Creating multi tiered applications Index.

Note that for DataSnap, you need to have the Delphi Enterprise as minimum edition, and this won't work with a CGI webservices.

Another solution (less options, but gets the data across from the server to the client), is to expose the TClientDataSet's internal data as XML, provide that through a method on your CGI Web Service, than on the client side put that XML into a TClientDataSet again.

I'm not sure if that is within the Delphi licensing terms (they might prohibit using TClientDataSet for doing multi-tier work), but it should work.

Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154