Delphi 7 WEB Service Client Sorunu

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Salih
Üye
Mesajlar: 250
Kayıt: 11 Mar 2004 05:36

Delphi 7 WEB Service Client Sorunu

Mesaj gönderen Salih »

Merhaba,

Hiç WEB servis deneyimim yok, C# ile yazılmış bir WEB servise Delphi 7 ile bağlanmam ve işin de mayıs sonuna yetişmesi gerekiyor. Bir kaç gündür internette araştırmalar yaparak aşağıdaki şekilde bir deneme oluşturdum. Servise bağlanmaya kalktığım anda access violation hatası alıyorum.

Yardımcı olacaklara şimdiden müteşekkirim. Saygılar,

Kod: Tümünü seç

Project DeneProje1.exe raised exception class EAccessViolation with message 'Access violation at address 004036FC in module 'DeneProje1.exe'. Read of address FFFFFFDD'. Process stopped. Use Step or Run to continue.
WSDL den oluşturulan Unit şu şekilde :

Kod: Tümünü seç

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : httP://gbo.isicamciyiz.biz/thirdparty.asmx?WSDL
// Encoding : utf-8
// Version  : 1.0
// (11.05.2016 14:27:28 - 1.33.2.5)
// ************************************************************************ //

unit thirdparty;
interface
uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;
type

  // ************************************************************************ //
  // The following types, referred to in the WSDL document are not being represented
  // in this file. They are either aliases[@] of other types represented or were referred
  // to but never[!] declared in the document. The types from the latter category
  // typically map to predefined/known XML or Borland types; however, they could also 
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:string          - "http://www.w3.org/2001/XMLSchema"
  // !:int             - "http://www.w3.org/2001/XMLSchema"
  // !:decimal         - "http://www.w3.org/2001/XMLSchema"
  // !:boolean         - "http://www.w3.org/2001/XMLSchema"

  GBO                  = class;                 { "http://tempuri.org/" }
  Yanit                = class;                 { "http://tempuri.org/" }
  Urun                 = class;                 { "http://tempuri.org/" }

  { "http://tempuri.org/" }
  urunSeri = (C, S, K);

  // ************************************************************************ //
  // Namespace : http://tempuri.org/
  // ************************************************************************ //
  GBO = class(TRemotable)
  private
    Fserviceuser: WideString;
    Fservicepassword: WideString;
    FcariId: WideString;
    Fcaripassword: WideString;
    FmusteriAdSoyad: WideString;
    FfirmaAdi: WideString;
    FfaturaTarihi: WideString;
    FfaturaNo: WideString;
    FvergiNo: WideString;
  published
    property serviceuser: WideString read Fserviceuser write Fserviceuser;
    property servicepassword: WideString read Fservicepassword write Fservicepassword;
    property cariId: WideString read FcariId write FcariId;
    property caripassword: WideString read Fcaripassword write Fcaripassword;
    property musteriAdSoyad: WideString read FmusteriAdSoyad write FmusteriAdSoyad;
    property firmaAdi: WideString read FfirmaAdi write FfirmaAdi;
    property faturaTarihi: WideString read FfaturaTarihi write FfaturaTarihi;
    property faturaNo: WideString read FfaturaNo write FfaturaNo;
    property vergiNo: WideString read FvergiNo write FvergiNo;
  end;

  // ************************************************************************ //
  // Namespace : http://tempuri.org/
  // ************************************************************************ //
  Yanit = class(TRemotable)
  private
    FproductTable: WideString;
    FQRcode: WideString;
    FQRrefno: WideString;
    FerrorMsg: WideString;
  published
    property productTable: WideString read FproductTable write FproductTable;
    property QRcode: WideString read FQRcode write FQRcode;
    property QRrefno: WideString read FQRrefno write FQRrefno;
    property errorMsg: WideString read FerrorMsg write FerrorMsg;
  end;

  // ************************************************************************ //
  // Namespace : http://tempuri.org/
  // ************************************************************************ //
  Urun = class(TRemotable)
  private
    FurunSeri: urunSeri;
    Fadet: Integer;
    Fmetrekare: TXSDecimal;
    FucluSistem: Boolean;
    FT: Boolean;
    FR: Boolean;
    FRF: Boolean;
    FL: Boolean;
    FAL: Boolean;
  public
    destructor Destroy; override;
  published
    property urunSeri: urunSeri read FurunSeri write FurunSeri;
    property adet: Integer read Fadet write Fadet;
    property metrekare: TXSDecimal read Fmetrekare write Fmetrekare;
    property ucluSistem: Boolean read FucluSistem write FucluSistem;
    property T: Boolean read FT write FT;
    property R: Boolean read FR write FR;
    property RF: Boolean read FRF write FRF;
    property L: Boolean read FL write FL;
    property AL: Boolean read FAL write FAL;
  end;

  // ************************************************************************ //
  // Namespace : http://tempuri.org/
  // soapAction: http://tempuri.org/%operationName%
  // transport : http://schemas.xmlsoap.org/soap/http
  // binding   : thirdpartySoap
  // service   : thirdparty
  // port      : thirdpartySoap
  // URL       : http://gbo.isicamciyiz.biz/thirdparty.asmx
  // ************************************************************************ //
  thirdpartySoap = interface(IInvokable)
  ['{C0A37DD1-954E-2D47-CDAE-8C814EEB97F7}']
    function  garantiBelgesiOlustur(const garantiBelgesi: GBO): Yanit; stdcall;
    procedure urunEkle(const yeniurun: Urun); stdcall;
  end;

function GetthirdpartySoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): thirdpartySoap;
implementation

function GetthirdpartySoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): thirdpartySoap;
const
  defWSDL = 'httP://gbo.isicamciyiz.biz/thirdparty.asmx?WSDL';
  defURL  = 'http://gbo.isicamciyiz.biz/thirdparty.asmx';
  defSvc  = 'thirdparty';
  defPrt  = 'thirdpartySoap';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;
  try
    Result := (RIO as thirdpartySoap);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
  finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;

destructor Urun.Destroy;
begin
  if Assigned(Fmetrekare) then
    Fmetrekare.Free;
  inherited Destroy;
end;

initialization
  InvRegistry.RegisterInterface(TypeInfo(thirdpartySoap), 'http://tempuri.org/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(thirdpartySoap), 'http://tempuri.org/%operationName%');
  RemClassRegistry.RegisterXSInfo(TypeInfo(urunSeri), 'http://tempuri.org/', 'urunSeri');
  RemClassRegistry.RegisterXSClass(GBO, 'http://tempuri.org/', 'GBO');
  RemClassRegistry.RegisterXSClass(Yanit, 'http://tempuri.org/', 'Yanit');
  RemClassRegistry.RegisterXSClass(Urun, 'http://tempuri.org/', 'Urun');

end.
Oluşturduğum kodlar :

Kod: Tümünü seç

implementation
    uses thirdparty;
var
  yGBO   : GBO;
  yUrun  : Urun;
  ySonuc : Yanit;
  servis1 : thirdpartysoap;
{$R *.dfm}
procedure TGrnForm.FormCreate(Sender: TObject);
begin
  yGBO  := GBO.Create;
  yUrun := Urun.Create;
  ySonuc:= Yanit.Create;
  servis1 := GetthirdpartySoap (true,'',nil);
//  servis1 := GetthirdpartySoap ();
end;

procedure TGrnForm.BtnBelgeEkleClick(Sender: TObject);
begin
  yGBO.FreeInstance;
  ySonuc.FreeInstance;
  yGBO.serviceuser := '';
  yGBO.servicepassword := '';
  yGBO.cariId := '100226';
  yGBO.caripassword := '121240SA';
  yGBO.faturaNo := EdFatNo.Text;
  yGBO.faturaTarihi := EdFatTarih.Text;
  yGBO.firmaAdi := EdBayi.Text;
//  yGBO.vergiNo := EdVergiNo.Text;
  yGBO.musteriAdSoyad := EdMusteri.Text;
// Aşağıdakilerin her ikisinde de aynı hata mesajını alıyorum
  ySonuc := servis1.garantiBelgesiOlustur(yGBO);
//  ySonuc := (HTTPRIO1 as thirdPartySoap).garantiBelgesiOlustur(yGBO);
  yGBO.Free;
end;

procedure TGrnForm.BtnUrunEkleClick(Sender: TObject);
var
  XsDec : TxsDecimal;
begin
  yUrun.FreeInstance;
  yUrun.adet := strToInt(EDAdet.Text);
  XsDec := TXSDecimal.Create;
  XsDec.DecimalString := Format('%f', [StrToFloat(edAlan.Text)]);
  yurun.metrekare := xsdec;
  if EdSeri.Text = 'C' then yUrun.urunSeri := C;
  if EdSeri.Text = 'S' then yUrun.urunSeri := S;
  if EdSeri.Text = 'K' then yUrun.urunSeri := K;
// Aşağıdakilerin her ikisinde de aynı hata mesajını alıyorum
//  servis1.urunEkle(yUrun);
   (HTTPRIO1 as thirdpartySoap).urunekle(yUrun);
end;
Sevgi, Saygı.....
Kullanıcı avatarı
csunguray
Üye
Mesajlar: 855
Kayıt: 09 Ara 2006 05:08
Konum: Adana
İletişim:

Re: Delphi 7 WEB Service Client Sorunu

Mesaj gönderen csunguray »

Web servisini çağırırken aşağıdaki kalıbı kullanın.

Kod: Tümünü seç

procedure TForm1.BtnUrunEkleClick(Sender: TObject);
var
  Servis: thirdpartySoap;
  Giris: Urun;
  //Sonuc: ServisSonuc;
  XsDec : TxsDecimal;
begin
  inherited;
  Screen.Cursor := crSQLWait;
  try
    HTTPRIO1.HTTPWebNode.UseUTF8InHeader := True;
    Servis := GetthirdpartySoap(False, 'http://gbo.isicamciyiz.biz/thirdparty.asmx', HTTPRIO1);
    Giris := Urun.Create;
    Giris.adet := strToInt(EDAdet.Text);
    XsDec := TXSDecimal.Create;
    XsDec.DecimalString := Format('%f', [StrToFloat(edAlan.Text)]);
    Giris.metrekare := xsdec;
    if EdSeri.Text = 'C' then Giris .urunSeri := C;
    if EdSeri.Text = 'S' then Giris .urunSeri := S;
    if EdSeri.Text = 'K' then Giris .urunSeri := K;
    Servis.urunEkle(Giris);
    // Urun ekle bir fonksiyon değil procedure olarak yapılandırılmış. Saçma 
    // yani. En azından bir sonuç kodu falan dönderselerdi iyi olurdu. 
    // Sonuc := Servis.urunEkle(Giris); 
  finally
    Giris.Free;
    //if Sonuc <> nil then Sonuc.Free;
    Screen.Cursor := crDefault;
  end;
end;

C. Sunguray
csunguray at netbilisim.kom
Net Bilişim Hizmetleri

Sıradan her programcı bilgisayarın anlayabileceği kodlar yazabilir.
Sadece iyi programcılar insanların da anlayabileceği kodlar yazarlar.
Martin Fowler (http://martinfowler.com/)
Salih
Üye
Mesajlar: 250
Kayıt: 11 Mar 2004 05:36

Re: Delphi 7 WEB Service Client Sorunu

Mesaj gönderen Salih »

Cevabınız için çok teşekkürler csunguray hocam. Yapıyı yazdığınız şekilde değiştirdim ve Servis.UrunEkle hata vermeden çalıştı.

Servis.garantiBelgesiOlustur satırına geldiğinde ise

Kod: Tümünü seç

Project DeneProje1.exe raised exception class ERemotableException with message
'System.Web.Services.Protocols.SoapException: Server was unable to process request.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.

   at thirdparty.garantiBelgesiOlustur(GBO garantiBelgesi) in 
e:\inetpub\wwwroot\xxxx\App_Code\thirdparty.cs:line 46
  
şeklinde hata veriyor.
PS:Sistem gereği bir veya bir kaç defa urunekle'yi çalıştırıp eklenecek ürünler bitince garantiBelgesiOlustur'u çalıştırıyoruz.

Kod: Tümünü seç

procedure TGrnForm.FormCreate(Sender: TObject);
begin
  yGBO  := GBO.Create;
  yUrun := Urun.Create;
  ySonuc:= Yanit.Create;
end;

procedure TGrnForm.BtnBelgeEkleClick(Sender: TObject);
begin
  inherited;
  Screen.Cursor := crSQLWait;
  try
    HTTPRIO1.HTTPWebNode.UseUTF8InHeader := True;
    Servis := GetthirdpartySoap(False, 'http://gbo.isicamciyiz.biz/thirdparty.asmx', HTTPRIO1);
    yGBO := GBO.Create;
    ySonuc := Yanit.Create;
    yGBO.serviceuser := '';
    yGBO.servicepassword := '';
    yGBO.cariId := '100226';
    yGBO.caripassword := '11111111';
    yGBO.faturaNo := EdFatNo.Text;
    yGBO.faturaTarihi := EdFatTarih.Text;
    yGBO.firmaAdi := EdBayi.Text;
    yGBO.vergiNo := EdVergiNo.Text;
    yGBO.musteriAdSoyad := EdMusteri.Text;
    ySonuc := Servis.garantiBelgesiOlustur(yGBO);
  finally
    yGBO.Free;
    if ySonuc <> nil then ySonuc.Free;
    Screen.Cursor := crDefault;
  end;
end;

procedure TGrnForm.BtnUrunEkleClick(Sender: TObject);
var
//  Servis: thirdpartySoap;
//  yUrun: Urun;
  XsDec : TxsDecimal;
begin
  inherited;
  Screen.Cursor := crSQLWait;
  try
    HTTPRIO1.HTTPWebNode.UseUTF8InHeader := True;
    Servis := GetthirdpartySoap(False, 'http://gbo.isicamciyiz.biz/thirdparty.asmx', HTTPRIO1);
    yUrun := Urun.Create;
    yUrun.adet := strToInt(EDAdet.Text);
    XsDec := TXSDecimal.Create;
    XsDec.DecimalString := Format('%f', [StrToFloat(edAlan.Text)]);
    yUrun.metrekare := xsdec;
    if EdSeri.Text = 'C' then yUrun.urunSeri := C;
    if EdSeri.Text = 'S' then yUrun.urunSeri := S;
    if EdSeri.Text = 'K' then yUrun.urunSeri := K;
    Servis.urunEkle(yUrun);
    // Urun ekle bir fonksiyon değil procedure olarak yapılandırılmış. Saçma
    // yani. En azından bir sonuç kodu falan dönderselerdi iyi olurdu.
    // Sonuc := Servis.urunEkle(yUrun);
  finally
    yUrun.Free;
    //if Sonuc <> nil then Sonuc.Free;
    Screen.Cursor := crDefault;
  end;
end;
En son Salih tarafından 23 May 2016 12:34 tarihinde düzenlendi, toplamda 1 kere düzenlendi.
Sevgi, Saygı.....
Kullanıcı avatarı
csunguray
Üye
Mesajlar: 855
Kayıt: 09 Ara 2006 05:08
Konum: Adana
İletişim:

Re: Delphi 7 WEB Service Client Sorunu

Mesaj gönderen csunguray »

Bu hatayı doldurman gereken bazı alanları boş geçtiğin için verir. İçine değer atmayacak olsan bile değerleri Create etmelisin. Sanırım VergiNo sahasına atama yapmamışsın. Vergi No olmasa bile

Kod: Tümünü seç

yGBO.vergiNo := '';


şeklinde atama yap ve o şekilde dene.
C. Sunguray
csunguray at netbilisim.kom
Net Bilişim Hizmetleri

Sıradan her programcı bilgisayarın anlayabileceği kodlar yazabilir.
Sadece iyi programcılar insanların da anlayabileceği kodlar yazarlar.
Martin Fowler (http://martinfowler.com/)
Salih
Üye
Mesajlar: 250
Kayıt: 11 Mar 2004 05:36

Re: Delphi 7 WEB Service Client Sorunu

Mesaj gönderen Salih »

Teşekkürler Hocam,

9 tane string değişken var ve hepsine atama yapmış durumdayım aslında :

Kod: Tümünü seç

    
    ySonuc := Yanit.Create;
    yGBO.serviceuser := '';
    yGBO.servicepassword := '';
    yGBO.cariId := '1234';
    yGBO.caripassword := '1234abc';
    yGBO.faturaNo := EdFatNo.Text;
    yGBO.faturaTarihi := EdFatTarih.Text;
    yGBO.firmaAdi := EdBayi.Text;
    yGBO.vergiNo := EdVergiNo.Text;
En son Salih tarafından 16 May 2016 06:09 tarihinde düzenlendi, toplamda 1 kere düzenlendi.
Sevgi, Saygı.....
Salih
Üye
Mesajlar: 250
Kayıt: 11 Mar 2004 05:36

Re: Delphi 7 WEB Service Client Sorunu

Mesaj gönderen Salih »

Değişkenlere atama yaptığım halde hepsi sunucuya boş olarak gidiyordu. Bunun nedeni de WSDL import işleminin

Kod: Tümünü seç

InvRegistry.RegisterInvokeOptions(TypeInfo(Service1Soap), ioDocument);
satırını eklememesi imiş.

WSDL importer tarafından oluşturulan kodların sonuna bu satırı ekleyince sorun halloldu :

Kod: Tümünü seç

initialization
  InvRegistry.RegisterInterface(TypeInfo(thirdpartySoap), 'http://tempuri.org/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(thirdpartySoap), 'http://tempuri.org/%operationName%');
  RemClassRegistry.RegisterXSInfo(TypeInfo(urunSeri), 'http://tempuri.org/', 'urunSeri');
  RemClassRegistry.RegisterXSClass(GBO, 'http://tempuri.org/', 'GBO');
  RemClassRegistry.RegisterXSClass(Yanit, 'http://tempuri.org/', 'Yanit');
  RemClassRegistry.RegisterXSClass(Urun, 'http://tempuri.org/', 'Urun');
  InvRegistry.RegisterInvokeOptions(TypeInfo(thirdpartySoap), ioDocument);
end.
Konu ile ilgili ipuçları için şu yazılara bakılabilir :

Kod: Tümünü seç

http://www.delphigroups.info/2/5/344488.html
https://www.bobswart.nl/weblog/Blog.aspx?RootId=5:798
Sevgi, Saygı.....
Cevapla