Soap Header Interface Not Supported

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
3ddark
Üye
Mesajlar: 89
Kayıt: 14 Eyl 2010 10:55
Konum: İstanbul

Soap Header Interface Not Supported

Mesaj gönderen 3ddark »

Client Form Unit

Kod: Tümünü seç

unit MainClient;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IWebService1, BaseForm,
  Vcl.ExtCtrls, Editfrht, Memofrht, Vcl.Imaging.GIFImg, dxGDIPlusClasses,
  Soap.InvokeRegistry, Soap.Rio, Soap.SOAPHTTPClient;

type
  TFormMainClient = class(TFormBase)
    PanelAnaMenu: TPanel;
    Button1: TButton;
    mmoTestData: TMemofrht;
    Splitter1: TSplitter;
    Panel1: TPanel;
    mmoAfter: TMemofrht;
    Splitter2: TSplitter;
    mmoBefore: TMemofrht;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject); override;
    procedure HTTPRIO1BeforeExecute(const MethodName: string;
      SOAPRequest: TStream);
    procedure HTTPRIO1AfterExecute(const MethodName: string;
      SOAPResponse: TStream);
  private

  public
    IServiceERP : IWebService;

    procedure SecurityHeaderEkle;
  end;

var
  FormMainClient: TFormMainClient;

implementation

{$R *.dfm}

uses Genel, Loading;

procedure TFormMainClient.SecurityHeaderEkle;
var
  securityHeader: TSecurityHeader;
begin
  securityHeader := TSecurityHeader.Create;
  try
    securityHeader.Identification := 'guvenlik_kodu';
    with IServiceERP as ISOAPHeaders do
    begin
      Send(TSOAPHeader(securityHeader));
    end;
  finally
//    header.Free;
  end;
end;

procedure TFormMainClient.Button1Click(Sender: TObject);
var
  nIndex: Integer;
  kullanicilar : TArKullanicilar;
begin
  IServiceERP := GetIWebService();
  SecurityHeaderEkle;   //**************************BURASI İPTAL
  kullanicilar := IServiceERP.GetEmployeeName;

  mmoTestData.Clear;

  for nIndex := 0 to Length(kullanicilar) - 1 do
  begin
    mmoTestData.Lines.Add(IntToStr(kullanicilar[nIndex].Id) + ' ' +
                          BoolToStr(kullanicilar[nIndex].Validity) + ' ' +
                          kullanicilar[nIndex].KullaniciAdi + ' ' +
                          kullanicilar[nIndex].KullaniciSifre + ' ' +
                          BoolToStr(kullanicilar[nIndex].IsAktif) + ' ' +
                          BoolToStr(kullanicilar[nIndex].IsYonetici) + #13);
  end;

end;

procedure TFormMainClient.FormShow(Sender: TObject);
begin
  inherited;
  ButtonIptal.Caption := CAP_IPTAL_BUTTON;
  ButtonSil.Visible   := False;
  ButtonTamam.Visible := False;
  SpinButton.Visible  := False;

  statBase.Panels.Items[STBAR_KAYIT_SAYISI].Width := 0;

  PanelAnaMenu.Parent := PanelMain;
end;

procedure TFormMainClient.HTTPRIO1AfterExecute(const MethodName: string; SOAPResponse: TStream);
begin
  inherited;
  SOAPResponse.Position := 0;
  mmoAfter.Lines.LoadFromStream(SOAPResponse);
end;

procedure TFormMainClient.HTTPRIO1BeforeExecute(const MethodName: string; SOAPRequest: TStream);
begin
  inherited;
  mmoBefore.Lines.LoadFromStream(SOAPRequest);
end;

end.
Client WSDL Import Unit

Kod: Tümünü seç

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://localhost:8080/wsdl/IWebService
//  >Import : http://localhost:8080/wsdl/IWebService>0
//  >Import : http://localhost:8080/wsdl/IWebService>1
// Version  : 1.0
// (30.03.2015 20:57:10 - - $Rev: 69934 $)
// ************************************************************************ //

unit IWebService1;

interface

uses Soap.InvokeRegistry, Soap.SOAPHTTPClient, System.Types, Soap.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 Embarcadero types; however, they could also
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:boolean         - "http://www.w3.org/2001/XMLSchema"[Gbl]
  // !:string          - "http://www.w3.org/2001/XMLSchema"[Gbl]
  // !:int             - "http://www.w3.org/2001/XMLSchema"[Gbl]

  TSecurityHeader      = class;                 { "urn:WebServiceImpl"[Hdr][GblCplx] }
  TKullanicilar        = class;                 { "urn:WebServiceIntf"[GblCplx] }



  // ************************************************************************ //
  // XML       : TSecurityHeader, global, <complexType>
  // Namespace : urn:WebServiceImpl
  // Info      : Header
  // ************************************************************************ //
  TSecurityHeader = class(TSOAPHeader)
  private
    FIdentification: string;
    FUserName: string;
    FPassword: string;
  published
    property Identification: string  read FIdentification write FIdentification;
    property UserName:       string  read FUserName write FUserName;
    property Password:       string  read FPassword write FPassword;
  end;

  TArKullanicilar = array of TKullanicilar;     { "urn:WebServiceIntf"[GblCplx] }


  // ************************************************************************ //
  // XML       : TKullanicilar, global, <complexType>
  // Namespace : urn:WebServiceIntf
  // ************************************************************************ //
  TKullanicilar = class(TRemotable)
  private
    FId: Integer;
    FValidity: Boolean;
    FKullaniciAdi: string;
    FKullaniciSifre: string;
    FIsAktif: Boolean;
    FIsYonetici: Boolean;
  published
    property Id:             Integer  read FId write FId;
    property Validity:       Boolean  read FValidity write FValidity;
    property KullaniciAdi:   string   read FKullaniciAdi write FKullaniciAdi;
    property KullaniciSifre: string   read FKullaniciSifre write FKullaniciSifre;
    property IsAktif:        Boolean  read FIsAktif write FIsAktif;
    property IsYonetici:     Boolean  read FIsYonetici write FIsYonetici;
  end;


  // ************************************************************************ //
  // Namespace : urn:WebServiceIntf-IWebService
  // soapAction: urn:WebServiceIntf-IWebService#GetEmployeeName
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : rpc
  // use       : encoded
  // binding   : IWebServicebinding
  // service   : IWebServiceservice
  // port      : IWebServicePort
  // URL       : http://localhost:8080/soap/IWebService
  // ************************************************************************ //
  IWebService = interface(IInvokable)
  ['{F394E00A-013A-602A-29BF-70E6DD13CF52}']

    // Headers: TSecurityHeader:pInOut
    function  GetEmployeeName: TArKullanicilar; stdcall;
  end;

function GetIWebService(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): IWebService;

var
  RIO: THTTPRIO;

implementation
  uses System.SysUtils, BaseForm, MainClient;

function GetIWebService(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): IWebService;
const
  defWSDL = 'http://localhost:8080/wsdl/IWebService';
  defURL  = 'http://localhost:8080/soap/IWebService';
  defSvc  = 'IWebServiceservice';
  defPrt  = 'IWebServicePort';
var
  securityHeader: TSecurityHeader;
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;

//  securityHeader := TSecurityHeader.Create;
//  securityHeader.Identification := 'guvenlik_kodu';

//  RIO.SOAPHeaders.Send(TSOAPHeader(securityHeader));

  RIO.OnAfterExecute  := FormMainClient.HTTPRIO1AfterExecute;
  RIO.OnBeforeExecute := FormMainClient.HTTPRIO1BeforeExecute;

  try
    Result := (RIO as IWebService);
    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;


initialization
  { IWebService }
  InvRegistry.RegisterInterface(TypeInfo(IWebService), 'urn:WebServiceIntf-IWebService', '');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(IWebService), 'urn:WebServiceIntf-IWebService#GetEmployeeName');
  InvRegistry.RegisterHeaderClass(TypeInfo(IWebService), TSecurityHeader, 'TSecurityHeader', 'urn:WebServiceImpl');
  RemClassRegistry.RegisterXSClass(TSecurityHeader, 'urn:WebServiceImpl', 'TSecurityHeader');
  RemClassRegistry.RegisterXSInfo(TypeInfo(TArKullanicilar), 'urn:WebServiceIntf', 'TArKullanicilar');
  RemClassRegistry.RegisterXSClass(TKullanicilar, 'urn:WebServiceIntf', 'TKullanicilar');

end.
Server Intf Unit

Kod: Tümünü seç

unit WebServiceIntf;

interface

uses
  Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns, System.Classes,
  Data.DB, ZAbstractRODataset, ZAbstractDataset, ZDataset, ZAbstractConnection,
  ZConnection, DatabaseModel;

type

  TKullanicilar = class(TRemotable)
  private
    FId               : Integer;
    FValidity         : Boolean;
    FKullaniciAdi      : AnsiString;
    FKullaniciSifre   : AnsiString;
    FIsAktif          : Boolean;
    FIsYonetici       : Boolean;
  published
    property Id                 : Integer     read FId                    write FId;
    property Validity           : Boolean     read FValidity              write FValidity;
    property KullaniciAdi       : AnsiString  read FKullaniciAdi          write FKullaniciAdi;
    property KullaniciSifre     : AnsiString  read FKullaniciSifre        write FKullaniciSifre;
    property IsAktif            : Boolean     read FIsAktif               write FIsAktif;
    property IsYonetici         : Boolean     read FIsYonetici            write FIsYonetici;
  public
    constructor Create();
  end;

  TArKullanicilar = array of TKullanicilar;

  IWebService = interface(IInvokable)
  ['{4FC64738-DE88-4D55-AD47-8E697DADAB99}']

    function GetEmployeeName(): TArKullanicilar; stdcall;
  end;

implementation

constructor TKullanicilar.Create();
begin
  inherited;
  //
end;

initialization
  { Invokable interfaces must be registered }
  InvRegistry.RegisterInterface(TypeInfo(IWebService));
end.
Servis Impl Unit

Kod: Tümünü seç

unit WebServiceImpl;

interface

uses
  Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns, WebServiceIntf, System.Classes,
  Data.DB, ZAbstractRODataset, ZAbstractDataset, ZDataset, ZAbstractConnection,
  ZConnection, System.SysUtils, DatabaseModel;

type
  TSecurityHeader = class(TSOAPHeader)
  private
    FIdentification: string;
    FPassword: string;
    FUserName: string;
    procedure SetIdentification(const Value: string);
    procedure SetPassword(const Value: string);
    procedure SetUserName(const Value: string);
  published
    property Identification : string read FIdentification write SetIdentification;
    property UserName : string read FUserName write SetUserName;
    property Password : string read FPassword write SetPassword;
  end;

type
  TWebService = class(TInvokableClass, IWebService)
  public
    model : TDatabaseModel;
    secureHeader : TSecurityHeader;

    function GetEmployeeName(): TArKullanicilar; stdcall;
    procedure checkHeader(); stdcall;
  end;

implementation

procedure TWebService.checkHeader;
var   header  : TSecurityHeader;
begin
  with Self as ISOAPHeaders do
  begin
    Get(TSecurityHeader, TSOAPHeader(header));
    if (header = nil) or (TSecurityHeader(header).Identification <> 'guvenlik_kodu') then
    begin
      raise Exception.Create('header bilgisi yok veya doğru degil');
    end;
  end;
end;

function TWebService.GetEmployeeName: TArKullanicilar; stdcall;
var   nIndex : Integer;
begin
  checkHeader;      //**************************BURASI İPTAL

  model := TDatabaseModel.Create(nil);
  with model do
  begin
    Query.Close;
    Query.SQL.Clear;
    Query.SQL.Text := ' SELECT id, validity, kullanici_adi, kullanici_sifre, is_aktif, is_yonetici FROM kullanicilar ';
    Query.Open;
    Query.First;

    SetLength(Result, Query.RecordCount);

    nIndex := 0;
    while not Query.Eof do
    begin
      Result[nIndex]  := TKullanicilar.Create;
      Result[nIndex].Id                 := Query.FieldByName('id').AsInteger;
      Result[nIndex].Validity           := Query.FieldByName('validity').AsBoolean;
      Result[nIndex].KullaniciAdi       := Query.FieldByName('kullanici_adi').AsAnsiString;
      Result[nIndex].KullaniciSifre     := Query.FieldByName('kullanici_sifre').AsAnsiString;
      Result[nIndex].IsAktif            := Query.FieldByName('is_aktif').AsBoolean;
      Result[nIndex].IsYonetici         := Query.FieldByName('is_yonetici').AsBoolean;

      Inc(nIndex);

      Query.Next;
    end;
  end;
end;

procedure TSecurityHeader.SetIdentification(const Value: string);
begin
  FIdentification := Value;
end;

procedure TSecurityHeader.SetPassword(const Value: string);
begin
  FPassword := Value;
end;

procedure TSecurityHeader.SetUserName(const Value: string);
begin
  FUserName := Value;
end;

initialization
{ Invokable classes must be registered }
   InvRegistry.RegisterInvokableClass(TWebService);
   InvRegistry.RegisterHeaderClass(TypeInfo(IWebService), TSecurityHeader);
end.
Değerli hocalarım. Ben SOAP server client deneme yaptım. Header bilgisi olmadan düzgün bir şekilde çalışıyor. XML içeriğini görüyorum. Server tarafından database içinden istediğim bilgileri gönderiyorum fakat header bilgisi eklemek istediğimde forumda ve google aradım bir sürü örnek var. Örnekleri inceledim (hatta denemek için aynısını yazdım). Fakat header bilgisini bir türlü düzgün bir şekilde gönderemedim. Sorun nereden kaynaklanıyor. Nereyi görmüyorum kaçırıyorum. Header eklemek isteyince
Interface Not Supported
hatasını alıyorum.

Bulduğum örnekler : http://stackoverflow.com/questions/1375 ... -in-delphihttp://docwiki.embarcadero.com/RADStudi ... AP_Headers
PostgreSQL - Delphi - Linux :!:
3ddark
Üye
Mesajlar: 89
Kayıt: 14 Eyl 2010 10:55
Konum: İstanbul

Re: Soap Header Interface Not Supported

Mesaj gönderen 3ddark »

Kod: Tümünü seç

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
	<SOAP-ENV:Header SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS1="urn:WebServiceImpl">
		<NS1:TSecurityHeader xsi:type="NS1:TSecurityHeader">
			<Identification xsi:type="xsd:string">guvenlik_kodu</Identification>
			<UserName xsi:type="xsd:string"></UserName>
			<Password xsi:type="xsd:string"></Password>
		</NS1:TSecurityHeader>
	</SOAP-ENV:Header>
	
	<SOAP-ENV:Body xmlns:NS2="urn:WebServiceIntf-IWebService" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
		<NS2:GetEmployeeName/>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Sanırım benim server tarafında okumada sorunum var. Kodun gönderme tarafında Reuqest XML paket içeriğini incelediğimde headerin ekli olduğunu görebiliyorum. Sorunu çözersem burada bildirimi yapacağım.
PostgreSQL - Delphi - Linux :!:
xxxjedixxx
Üye
Mesajlar: 216
Kayıt: 10 Ara 2013 03:50

Re: Soap Header Interface Not Supported

Mesaj gönderen xxxjedixxx »

Merhaba,
Bir kaç ay önce ben de aynı sıkıntı ile karşılaştım. Çözüm aradım ama bulamadım. Ben de sorunuza gelecek yanıtları merak ediyorum.

Ben çözüm bulamadığım için farklı bir yöntem ile devam ettim. Oturum açma ile kendime ait bir algoritma ile ticket kodu üretip onu kullanıcıya geri gönderiyorum. Bu ticket kodunu da kullanıcı adı ve geçerlilik süresi ile birlikte veri tabanında saklıyorum. Web servisteki her fonksiyona da parametre olarak bu ticket kodunu ekledim. Böylelikle fonksiyon çağırıldığında önce ticket kodunun geçerliliğini kontrol ediyorum.
3ddark
Üye
Mesajlar: 89
Kayıt: 14 Eyl 2010 10:55
Konum: İstanbul

Re: Soap Header Interface Not Supported

Mesaj gönderen 3ddark »

Sayın xxxjedixxx,
Acaba sizin kullandığınız delphi sürümü nedir?
Ben bu işlemi XE7 de denedim. Versiyon sormamın nedeni Dr.Bob amca header ile ilgili örneği burada http://www.drbob42.com/examines/examinC7.htm yapmış. Bug mı var yoksa ben eksik veya yanlış bir şeyler yapıyorum.
Burada da XE ile yapılmış bir örnek var. https://www.youtube.com/watch?v=Jaa9lrwHQ5s
PostgreSQL - Delphi - Linux :!:
xxxjedixxx
Üye
Mesajlar: 216
Kayıt: 10 Ara 2013 03:50

Re: Soap Header Interface Not Supported

Mesaj gönderen xxxjedixxx »

Delphi7 ve Delphi XE7 her ikisinde de denedim fakat olmadı. Bulduğun örneklere bakıp denerim.
Cevapla