Web Servis TRemotable kullanımı

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Okann
Üye
Mesajlar: 81
Kayıt: 09 Tem 2010 02:55

Web Servis TRemotable kullanımı

Mesaj gönderen Okann »

Merhaba Arkadaşlar;

Bir web servis projem var. TRemotable kullanımında sorun yaşıyorum. Derledikten sonra aşağıdaki uyarıyı veriyor.
[dcc32 Warning] WSImpl.pas(647): W1035 Return value of function 'TWS.LicenseControl' might be undefined
Neden tanımsız gibi görüyor bilemiyorum. Web servisi başka bir uygulamadan çağırıp test ettiğimde de AccessViolation veriyor. Hatayı nerede yaptığım konusunda yardımcı olursanız çok sevinirim.

Kod: Tümünü seç

unit WSIntf;

interface

uses
  System.Types,
  Soap.XSBuiltIns,
  Soap.InvokeRegistry,
  System.Generics.Collections;

type
  TLicenseInfo = class(TRemotable)
  private
    FMailService: ShortInt;
    FLicenseStatus: ShortInt;
    FAccountBalance: ShortInt;
    FMaterialInventory: ShortInt;
  published
    property MailService: ShortInt read FMailService write FMailService;
    property LicenseStatus: ShortInt read FLicenseStatus write FLicenseStatus;
    property AccountBalance: ShortInt read FAccountBalance write FAccountBalance;
    property MaterialInventory: ShortInt read FMaterialInventory write FMaterialInventory;
  end;

type
  IWS = interface(IInvokable)
  ['{5AB2605F-41E0-4A01-9962-1D0EE093D3C7}']
    function LicenseControl(ProductID, FirmID, AccountName: string): TLicenseInfo; stdcall;
  end;

implementation

initialization
  InvRegistry.RegisterInterface(TypeInfo(IWS));
  RemClassRegistry.RegisterXSInfo(TypeInfo(TLicenseInfo));

finalization
  InvRegistry.UnRegisterInterface(TypeInfo(IWS));
  RemClassRegistry.UnRegisterXSInfo(TypeInfo(TLicenseInfo));

end.




unit WSImpl;

interface

uses
  System.Types,
  System.SysUtils,
  System.DateUtils,
  System.Generics.Collections,
  Soap.XSBuiltIns,
  Soap.InvokeRegistry,
  WSIntf,
  SQLServerUniProvider,
  Xml.XMLIntf,
  Xml.XMLDoc,
  UniProvider,
  DBAccess,
  Data.DB,
  MemDS,
  Uni;

type
  TWS = class(TInvokableClass, IWS)
  public
    function LicenseControl(ProductID, FirmID, AccountName: string): TLicenseInfo; stdcall;
  end;

implementation

{ TWS }

uses unParams;

function TWS.LicenseControl(ProductID, FirmID, AccountName: string): TLicenseInfo;
var
  db: TUniConnection;
  Q: TUniQuery;
  AppID: Integer;
  FMailService,
  FLicenseStatus,
  FAccountBalance,
  FMaterialInventory: ShortInt;
begin
  db := TUniConnection.Create(nil);
  Q := TUniQuery.Create(nil);
  Q.Connection := db;
  FMailService := 0;
  FLicenseStatus := 0;
  FAccountBalance := 0;
  FMaterialInventory := 0;
  try
    try
      ....
    except
      FMailService := -1;
      FLicenseStatus := -1; 
      FAccountBalance := -1;
      FMaterialInventory := -1;
    end;
  finally
    FreeAndNil(Q);
    FreeAndNil(db);
    Result.LicenseStatus := FLicenseStatus;
    Result.MailService := FMailService;
    Result.AccountBalance := FAccountBalance;
    Result.MaterialInventory := FMaterialInventory;
  end;
end;

initialization
   InvRegistry.RegisterInvokableClass(TWS);

end.
ertank
Kıdemli Üye
Mesajlar: 1650
Kayıt: 12 Eyl 2015 12:45

Re: Web Servis TRemotable kullanımı

Mesaj gönderen ertank »

Merhaba,

Aşağıdaki şekilde değiştirildiği zaman halen uyarı alıyor musunuz?

Kod: Tümünü seç

function TWS.LicenseControl(ProductID, FirmID, AccountName: string): TLicenseInfo;
var
  db: TUniConnection;
  Q: TUniQuery;
  AppID: Integer;
  FMailService,
  FLicenseStatus,
  FAccountBalance,
  FMaterialInventory: ShortInt;
begin
  Result.LicenseStatus := -1;
  Result.MailService := -1;
  Result.AccountBalance := -1;
  Result.MaterialInventory := -1;

  db := nil;
  q := nil;
  try
    db := TUniConnection.Create(nil);
    Q := TUniQuery.Create(nil);
    Q.Connection := db;
    FMailService := 0;
    FLicenseStatus := 0;
    FAccountBalance := 0;
    FMaterialInventory := 0;
    try
      try
        ....
      except
        FMailService := -1;
        FLicenseStatus := -1; 
        FAccountBalance := -1;
        FMaterialInventory := -1;
      end;
    finally
      Result.LicenseStatus := FLicenseStatus;
      Result.MailService := FMailService;
      Result.AccountBalance := FAccountBalance;
      Result.MaterialInventory := FMaterialInventory;
    end;
  finally
    Q.Free();
    db.Free();
  end;
end;
Okann
Üye
Mesajlar: 81
Kayıt: 09 Tem 2010 02:55

Re: Web Servis TRemotable kullanımı

Mesaj gönderen Okann »

Merhaba hocam,

Denedim fakat değişen bir şey olmadı. Oluşturduğum TLicenseInfo sınıfı ile ilgili bir problem olabilir mi acaba?
Okann
Üye
Mesajlar: 81
Kayıt: 09 Tem 2010 02:55

Re: Web Servis TRemotable kullanımı

Mesaj gönderen Okann »

Sorunu buldum.
Fonksiyon içinde Result := TLicenseInfo.Create; demek gerekiyormuş.
Cevapla