Access violation pour access a WebService

DavKli Messages postés 28 Date d'inscription mardi 10 mars 2009 Statut Membre Dernière intervention 31 octobre 2013 - 19 avril 2010 à 19:02
neo1667 Messages postés 1 Date d'inscription lundi 12 avril 2010 Statut Membre Dernière intervention 11 octobre 2010 - 11 oct. 2010 à 15:18
Bonjour a tous,

voila mon souci, j'ai une appli que utilise une service externe WebService. Ca marche super sur mon poste mais sur un poste sans delphi je obtient une "Access violation at adress 00C25935. Write of adress 00C25935."

Voici le code source des 2 unites (le deuxieme est genere automatiquement a l'importation du webservice) :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, TypInfo;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;
  
implementation

uses CurrencyConvertor;

{$R *.DFM}


procedure TForm1.Button1Click(Sender: TObject);
var
  ws: CurrencyConvertorSoap;
  Str1: string;
  Str2: String;
  int1: Integer;
begin
  Button1.Enabled := False;
  Ws := GetCurrencyConvertorSoap;
  for Int1 := 0 to ord(High(Currency))-1 do
  begin
    Str1 := GetEnumName(TypeInfo(Currency), integer(Int1));
    Str2 := Ws.ConversionRate(EUR, Currency(int1));
    Str2 := Str1 + ' - ' + Str2;
    Listbox1.Items.Add(Str2);
    Application.ProcessMessages;
  end;
  Button1.Enabled := True;
end;

end.


unit CurrencyConvertor;

interface

uses InvokeRegistry, SOAPHTTPClient, Dialogs, Types, XSBuiltIns;

type
  Currency = (
      AFA,
      ALL,
      DZD,
      ARS,
      AWG,
      AUD,
      BSD,
      BHD,
      BDT,
      BBD,
      BZD,
      BMD,
      BTN,
      BOB,
      BWP,
      BRL,
      GBP,
      BND,
      BIF,
      XOF,
      XAF,
      KHR,
      CAD,
      CVE,
      KYD,
      CLP,
      CNY,
      COP,
      KMF,
      CRC,
      HRK,
      CUP,
      CYP,
      CZK,
      DKK,
      DJF,
      DOP,
      XCD,
      EGP,
      SVC,
      EEK,
      ETB,
      EUR,
      FKP,
      GMD,
      GHC,
      GIP,
      XAU,
      GTQ,
      GNF,
      GYD,
      HTG,
      HNL,
      HKD,
      HUF,
      ISK,
      INR,
      IDR,
      IQD,
      ILS,
      JMD,
      JPY,
      JOD,
      KZT,
      KES,
      KRW,
      KWD,
      LAK,
      LVL,
      LBP,
      LSL,
      LRD,
      LYD,
      LTL,
      MOP,
      MKD,
      MGF,
      MWK,
      MYR,
      MVR,
      MTL,
      MRO,
      MUR,
      MXN,
      MDL,
      MNT,
      MAD,
      MZM,
      MMK,
      NAD,
      NPR,
      ANG,
      NZD,
      NIO,
      NGN,
      KPW,
      NOK,
      OMR,
      XPF,
      PKR,
      XPD,
      PAB,
      PGK,
      PYG,
      PEN,
      PHP,
      XPT,
      PLN,
      QAR,
      ROL,
      RUB,
      WST,
      STD,
      SAR,
      SCR,
      SLL,
      XAG,
      SGD,
      SKK,
      SIT,
      SBD,
      SOS,
      ZAR,
      LKR,
      SHP,
      SDD,
      SRG,
      SZL,
      SEK,
      CHF,
      SYP,
      TWD,
      TZS,
      THB,
      TOP,
      TTD,
      TND,
      TRL,
      USD,
      AED,
      UGX,
      UAH,
      UYU,
      VUV,
      VEB,
      VND,
      YER,
      YUM,
      ZMK,
      ZWD,
      TRY_
      );

  // ************************************************************************ //
  // Namespace : http://www.webserviceX.NET/
  // soapAction: http://www.webserviceX.NET/ConversionRate
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : document
  // binding   : CurrencyConvertorSoap
  // service   : CurrencyConvertor
  // port      : CurrencyConvertorSoap
  // URL       : http://www.webservicex.net/CurrencyConvertor.asmx
  // ************************************************************************ //
  CurrencyConvertorSoap = interface(IInvokable)
  ['{A1817D10-F9A2-B6F6-30E2-8FFB22ABBD60}']
    function  ConversionRate(const FromCurrency: Currency; const ToCurrency: Currency): String; stdcall;
  end;

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


implementation

function GetCurrencyConvertorSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): CurrencyConvertorSoap;
const
  defWSDL = 'http://www.webservicex.net/CurrencyConvertor.asmx?wsdl';
  defURL  = 'http://www.webservicex.net/CurrencyConvertor.asmx';
  defSvc  = 'CurrencyConvertor';
  defPrt  = 'CurrencyConvertorSoap';
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 CurrencyConvertorSoap);
    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
    Begin
      RIO.Free;
    end;
  end;
end;


initialization
  InvRegistry.RegisterInterface(TypeInfo(CurrencyConvertorSoap), 'http://www.webserviceX.NET/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(CurrencyConvertorSoap), 'http://www.webserviceX.NET/ConversionRate');
  InvRegistry.RegisterInvokeOptions(TypeInfo(CurrencyConvertorSoap), ioDocument);
  RemClassRegistry.RegisterXSInfo(TypeInfo(Currency), 'http://www.webserviceX.NET/', 'Currency');
  RemClassRegistry.RegisterExternalPropName(TypeInfo(Currency), 'TRY_', 'TRY');

end.

1 réponse

neo1667 Messages postés 1 Date d'inscription lundi 12 avril 2010 Statut Membre Dernière intervention 11 octobre 2010
11 oct. 2010 à 15:18
Bonjour,

j'arrive surement trop tard, mais au cas où, voici l'explication à votre problème :

http://www.delphigroups.info/2/6/346025.html

@++
Dany
0
Rejoignez-nous