Created
March 17, 2014 23:12
-
-
Save drgarcia1986/9610291 to your computer and use it in GitHub Desktop.
Aplicativo de exemplo referente a post de titulo "Recuperando o XML de uma requisição SOAP em Delphi" no blog http://drgarcia1986.wordpress.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ************************************************************************ // | |
// The types declared in this file were generated from data read from the | |
// WSDL File described below: | |
// WSDL : http://www.webservicex.net/CurrencyConvertor.asmx?WSDL | |
// >Import : http://www.webservicex.net/CurrencyConvertor.asmx?WSDL>0 | |
// Encoding : utf-8 | |
// Version : 1.0 | |
// (27/06/2013 19:13:01 - - $Rev: 45757 $) | |
// ************************************************************************ // | |
unit CurrencyConvertor; | |
interface | |
uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns; | |
const | |
IS_REF = $0080; | |
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. | |
// ************************************************************************ // | |
// !:string - "http://www.w3.org/2001/XMLSchema"[] | |
// !:double - "http://www.w3.org/2001/XMLSchema"[Gbl] | |
{$SCOPEDENUMS ON} | |
{ "http://www.webserviceX.NET/"[GblSmpl] } | |
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_ | |
); | |
{$SCOPEDENUMS OFF} | |
double_ = type Double; { "http://www.webserviceX.NET/"[GblElm] } | |
// ************************************************************************ // | |
// Namespace : http://www.webserviceX.NET/ | |
// soapAction: http://www.webserviceX.NET/ConversionRate | |
// transport : http://schemas.xmlsoap.org/soap/http | |
// style : document | |
// use : literal | |
// binding : CurrencyConvertorSoap12 | |
// service : CurrencyConvertor | |
// port : CurrencyConvertorSoap12 | |
// URL : http://www.webservicex.net/CurrencyConvertor.asmx | |
// ************************************************************************ // | |
CurrencyConvertorSoap = interface(IInvokable) | |
['{7A5B2A2E-A240-0304-FA58-F86D9AFAA52F}'] | |
function ConversionRate(const FromCurrency: Currency; const ToCurrency: Currency): Double; stdcall; | |
end; | |
// ************************************************************************ // | |
// Namespace : http://www.webserviceX.NET/ | |
// style : ???? | |
// use : ???? | |
// binding : CurrencyConvertorHttpGet | |
// service : CurrencyConvertor | |
// port : CurrencyConvertorHttpGet | |
// ************************************************************************ // | |
CurrencyConvertorHttpGet = interface(IInvokable) | |
['{44834808-BF25-E8E7-B6F8-2713C082359C}'] | |
function ConversionRate(const FromCurrency: string; const ToCurrency: string): double_; stdcall; | |
end; | |
// ************************************************************************ // | |
// Namespace : http://www.webserviceX.NET/ | |
// style : ???? | |
// use : ???? | |
// binding : CurrencyConvertorHttpPost | |
// service : CurrencyConvertor | |
// port : CurrencyConvertorHttpPost | |
// ************************************************************************ // | |
CurrencyConvertorHttpPost = interface(IInvokable) | |
['{A7CCBD67-8708-2EFA-72E9-D461EF46582A}'] | |
function ConversionRate(const FromCurrency: string; const ToCurrency: string): double_; stdcall; | |
end; | |
function GetCurrencyConvertorSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): CurrencyConvertorSoap; | |
function GetCurrencyConvertorHttpGet(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): CurrencyConvertorHttpGet; | |
function GetCurrencyConvertorHttpPost(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): CurrencyConvertorHttpPost; | |
implementation | |
uses SysUtils; | |
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 = 'CurrencyConvertorSoap12'; | |
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 | |
RIO.Free; | |
end; | |
end; | |
function GetCurrencyConvertorHttpGet(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): CurrencyConvertorHttpGet; | |
const | |
defWSDL = 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'; | |
defURL = ''; | |
defSvc = 'CurrencyConvertor'; | |
defPrt = 'CurrencyConvertorHttpGet'; | |
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 CurrencyConvertorHttpGet); | |
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; | |
function GetCurrencyConvertorHttpPost(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): CurrencyConvertorHttpPost; | |
const | |
defWSDL = 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'; | |
defURL = ''; | |
defSvc = 'CurrencyConvertor'; | |
defPrt = 'CurrencyConvertorHttpPost'; | |
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 CurrencyConvertorHttpPost); | |
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 | |
{ CurrencyConvertorSoap } | |
InvRegistry.RegisterInterface(TypeInfo(CurrencyConvertorSoap), 'http://www.webserviceX.NET/', 'utf-8'); | |
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(CurrencyConvertorSoap), 'http://www.webserviceX.NET/ConversionRate'); | |
InvRegistry.RegisterInvokeOptions(TypeInfo(CurrencyConvertorSoap), ioDocument); | |
InvRegistry.RegisterInvokeOptions(TypeInfo(CurrencyConvertorSoap), ioSOAP12); | |
{ CurrencyConvertorSoap.ConversionRate } | |
InvRegistry.RegisterMethodInfo(TypeInfo(CurrencyConvertorSoap), 'ConversionRate', '', | |
'[ReturnName="ConversionRateResult"]'); | |
{ CurrencyConvertorHttpGet } | |
InvRegistry.RegisterInterface(TypeInfo(CurrencyConvertorHttpGet), 'http://www.webserviceX.NET/', 'utf-8'); | |
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(CurrencyConvertorHttpGet), ''); | |
{ CurrencyConvertorHttpPost } | |
InvRegistry.RegisterInterface(TypeInfo(CurrencyConvertorHttpPost), 'http://www.webserviceX.NET/', 'utf-8'); | |
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(CurrencyConvertorHttpPost), ''); | |
RemClassRegistry.RegisterXSInfo(TypeInfo(Currency), 'http://www.webserviceX.NET/', 'Currency'); | |
RemClassRegistry.RegisterExternalPropName(TypeInfo(Currency), 'TRY_', 'TRY'); | |
RemClassRegistry.RegisterXSInfo(TypeInfo(double_), 'http://www.webserviceX.NET/', 'double_', 'double'); | |
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object frmWebserviceCliente: TfrmWebserviceCliente | |
Left = 0 | |
Top = 0 | |
BorderIcons = [biSystemMenu] | |
BorderStyle = bsSingle | |
Caption = 'Conversor de moeda' | |
ClientHeight = 606 | |
ClientWidth = 670 | |
Color = clBtnFace | |
Font.Charset = DEFAULT_CHARSET | |
Font.Color = clWindowText | |
Font.Height = -13 | |
Font.Name = 'Tahoma' | |
Font.Style = [] | |
OldCreateOrder = False | |
OnCreate = FormCreate | |
DesignSize = ( | |
670 | |
606) | |
PixelsPerInch = 96 | |
TextHeight = 16 | |
object lblResultado: TLabel | |
Left = 88 | |
Top = 44 | |
Width = 69 | |
Height = 16 | |
Caption = 'lblResultado' | |
end | |
object Label1: TLabel | |
Left = 8 | |
Top = 11 | |
Width = 30 | |
Height = 16 | |
Caption = 'From' | |
end | |
object Label2: TLabel | |
Left = 127 | |
Top = 11 | |
Width = 15 | |
Height = 16 | |
Caption = 'To' | |
end | |
object btnConverter: TButton | |
Left = 8 | |
Top = 41 | |
Width = 75 | |
Height = 25 | |
Caption = 'Converter' | |
TabOrder = 0 | |
OnClick = btnConverterClick | |
end | |
object mmRequest: TMemo | |
Left = 8 | |
Top = 72 | |
Width = 654 | |
Height = 233 | |
Anchors = [akLeft, akTop, akRight] | |
Lines.Strings = ( | |
'mmRequest') | |
ScrollBars = ssBoth | |
TabOrder = 1 | |
end | |
object mmResponse: TMemo | |
Left = 8 | |
Top = 328 | |
Width = 654 | |
Height = 270 | |
Anchors = [akLeft, akTop, akRight, akBottom] | |
Lines.Strings = ( | |
'mmResponse') | |
ScrollBars = ssBoth | |
TabOrder = 2 | |
end | |
object cmbFrom: TComboBox | |
Left = 44 | |
Top = 8 | |
Width = 77 | |
Height = 24 | |
Style = csDropDownList | |
TabOrder = 3 | |
end | |
object cmbTo: TComboBox | |
Left = 148 | |
Top = 8 | |
Width = 93 | |
Height = 24 | |
Style = csDropDownList | |
TabOrder = 4 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit Webservice.Client.View; | |
interface | |
uses | |
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, | |
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Soap.InvokeRegistry, | |
Soap.Rio, Soap.SOAPHTTPClient; | |
type | |
TfrmWebserviceCliente = class(TForm) | |
btnConverter: TButton; | |
lblResultado: TLabel; | |
mmRequest: TMemo; | |
mmResponse: TMemo; | |
cmbFrom: TComboBox; | |
cmbTo: TComboBox; | |
Label1: TLabel; | |
Label2: TLabel; | |
procedure btnConverterClick(Sender: TObject); | |
procedure FormCreate(Sender: TObject); | |
private | |
{ Private declarations } | |
procedure CarregarCombos(); | |
procedure httpRioBeforeExecute(const MethodName: string;SOAPRequest: TStream); | |
procedure httpRioAfterExecute(const MethodName: string; SOAPResponse: TStream); | |
public | |
{ Public declarations } | |
end; | |
var | |
frmWebserviceCliente: TfrmWebserviceCliente; | |
implementation | |
{$R *.dfm} | |
uses CurrencyConvertor, typInfo; | |
procedure TfrmWebserviceCliente.btnConverterClick(Sender: TObject); | |
var | |
_ccSoap : CurrencyConvertorSoap; | |
_rio : THTTPRIO; | |
begin | |
_rio := THTTPRIO.Create(nil); | |
_rio.OnBeforeExecute := Self.httpRioBeforeExecute; | |
_rio.OnAfterExecute := Self.httpRioAfterExecute; | |
_ccSoap := GetCurrencyConvertorSoap(false,EmptyStr,_rio); | |
try | |
lblResultado.Caption := Format('$%f',[_ccSoap.ConversionRate(Currency(cmbFrom.ItemIndex), Currency(cmbTo.ItemIndex))]); | |
finally | |
_ccSoap := nil; | |
end; | |
end; | |
procedure TfrmWebserviceCliente.CarregarCombos; | |
var | |
moeda : Currency; | |
begin | |
cmbFrom.Clear; | |
cmbTo.Clear; | |
for moeda := low(currency) to high(currency) do | |
begin | |
cmbFrom.Items.Add(GetEnumName(TypeInfo(Currency),ord(moeda))); | |
end; | |
cmbTo.Items.AddStrings(cmbFrom.Items); | |
cmbFrom.ItemIndex := 0; | |
cmbTo.ItemIndex := 0; | |
end; | |
procedure TfrmWebserviceCliente.FormCreate(Sender: TObject); | |
begin | |
ReportMemoryLeaksOnShutdown := true; | |
Self.CarregarCombos(); | |
end; | |
procedure TfrmWebserviceCliente.httpRioAfterExecute(const MethodName: string; | |
SOAPResponse: TStream); | |
begin | |
SOAPResponse.Position := 0; | |
mmResponse.Lines.LoadFromStream(SOAPResponse); | |
SOAPResponse.Position := 0; | |
end; | |
procedure TfrmWebserviceCliente.httpRioBeforeExecute(const MethodName: string; | |
SOAPRequest: TStream); | |
begin | |
SOAPRequest.Position := 0; | |
mmRequest.Lines.LoadFromStream(SOAPRequest); | |
SOAPRequest.Position := 0; | |
end; | |
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program WebserviceTestings; | |
uses | |
Vcl.Forms, | |
Webservice.Client.View in 'Webservice.Client.View.pas' {frmWebserviceCliente}, | |
CurrencyConvertor in 'CurrencyConvertor.pas'; | |
{$R *.res} | |
begin | |
Application.Initialize; | |
Application.MainFormOnTaskbar := True; | |
Application.CreateForm(TfrmWebserviceCliente, frmWebserviceCliente); | |
Application.Run; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment