Fórum Acessar webservices no delphi xe5 #458170
10/10/2013
0
Estou tentando consumir a WSDL : http://www.byjg.com.br/site/webservice.php/ws/cep?WSDL, no delphi xe5 for android.
Porem aparece um erro na execução
veja o código abaixo :
unit Principal;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Graphics, FMX.Forms, FMX.Dialogs, FMX.TabControl,
System.Actions, FMX.ActnList, FMX.StdCtrls, FMX.Layouts, FMX.Memo, FMX.Edit,
Soap.InvokeRegistry, Soap.Rio, Soap.SOAPHTTPClient;
type
TfmPrincipal = class(TForm)
TabControl1: TTabControl;
TabItem1: TTabItem;
TabItem2: TTabItem;
TopToolBar: TToolBar;
ToolBarLabel: TLabel;
TopToolBar1: TToolBar;
ToolBarLabel1: TLabel;
btnBack: TButton;
ActionList1: TActionList;
ChangeTabAction1: TChangeTabAction;
ChangeTabAction2: TChangeTabAction;
BottomToolBar: TToolBar;
btnNext: TSpeedButton;
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
HTTPRIO1: THTTPRIO;
procedure Button1Click(Sender: TObject);
{ Private declarations }
public
{ Public declarations }
end;
var
fmPrincipal: TfmPrincipal;
implementation
{$R *.fmx}
uses cep;
procedure TfmPrincipal.Button1Click(Sender: TObject);
var
ser: CEPServicePort;
begin
ser:= GetCEPServicePorT(false,'',HTTPRIO1);
memo1.lines.add( ser.obterLogradouroAuth(Edit1.Text,'usuario','senha'));
end;
end.
Form:
object fmPrincipal: TfmPrincipal
Left = 0
Top = 0
Caption = 'HeaderFooter'
ClientHeight = 359
ClientWidth = 598
FormFactor.Width = 1440
FormFactor.Height = 900
FormFactor.Devices = [dkDesktop]
DesignerMobile = True
DesignerWidth = 598
DesignerHeight = 384
DesignerDeviceName = 'Google Nexus 4'
DesignerOrientation = 1
DesignerOSVersion = ''
object TabControl1: TTabControl
Align = alClient
FullSize = True
Height = 311.000000000000000000
TabHeight = 49.000000000000000000
TabIndex = 0
TabOrder = 0
TabPosition = tpNone
Width = 598.000000000000000000
object TabItem1: TTabItem
WordWrap = False
Height = 8.000000000000000000
IsSelected = True
Position.X = 290.000000000000000000
Position.Y = 292.000000000000000000
TabOrder = 0
Text = 'TabItem1'
Width = 8.000000000000000000
object TopToolBar: TToolBar
Anchors = []
Height = 48.000000000000000000
TabOrder = 0
Width = 598.000000000000000000
object ToolBarLabel: TLabel
Align = alContents
Height = 48.000000000000000000
StyleLookup = 'toollabel'
Text = 'Title'
TextAlign = taCenter
Width = 598.000000000000000000
end
object btnNext: TSpeedButton
Action = ChangeTabAction1
Align = alRight
Height = 48.000000000000000000
Margins.Right = 5.000000000000000000
Position.X = 536.000000000000000000
Width = 57.000000000000000000
end
end
end
object TabItem2: TTabItem
WordWrap = False
Height = 8.000000000000000000
IsSelected = False
Position.X = 300.000000000000000000
Position.Y = 292.000000000000000000
TabOrder = 1
Text = 'TabItem2'
Width = 8.000000000000000000
object TopToolBar1: TToolBar
Anchors = []
Height = 48.000000000000000000
TabOrder = 0
Width = 598.000000000000000000
object ToolBarLabel1: TLabel
Align = alContents
Height = 48.000000000000000000
StyleLookup = 'toollabel'
Text = 'Title'
TextAlign = taCenter
Width = 598.000000000000000000
end
object btnBack: TButton
Action = ChangeTabAction2
Align = alLeft
Height = 48.000000000000000000
Margins.Left = 5.000000000000000000
Position.X = 5.000000000000000000
StyleLookup = 'backtoolbutton'
TabOrder = 1
Width = 65.000000000000000000
end
end
end
end
object BottomToolBar: TToolBar
Align = alBottom
Anchors = [akLeft]
Height = 48.000000000000000000
Position.Y = 311.000000000000000000
StyleLookup = 'bottomtoolbar'
TabOrder = 1
Width = 598.000000000000000000
end
object Button1: TButton
Height = 44.000000000000000000
Position.X = 160.000000000000000000
Position.Y = 56.000000000000000000
TabOrder = 2
Text = 'Pesquisar endere'#231'o'
Trimming = ttCharacter
Width = 201.000000000000000000
OnClick = Button1Click
end
object Edit1: TEdit
Touch.InteractiveGestures = [igLongTap, igDoubleTap]
TabOrder = 3
Text = '31030-130'
Position.X = 16.000000000000000000
Position.Y = 64.000000000000000000
Width = 129.000000000000000000
Height = 32.000000000000000000
KillFocusByReturn = False
end
object Memo1: TMemo
Touch.InteractiveGestures = [igPan, igLongTap, igDoubleTap]
Height = 153.000000000000000000
Position.X = 16.000000000000000000
Position.Y = 112.000000000000000000
TabOrder = 4
Width = 345.000000000000000000
end
object ActionList1: TActionList
Left = 272
Top = 8
object ChangeTabAction1: TChangeTabAction
CustomText = 'Next'
Tab = TabItem2
Transition = ttSlide
end
object ChangeTabAction2: TChangeTabAction
CustomText = ' Back'
Tab = TabItem1
Transition = ttSlide
end
end
object HTTPRIO1: THTTPRIO
HTTPWebNode.UseUTF8InHeader = True
HTTPWebNode.InvokeOptions = [soIgnoreInvalidCerts, soAutoCheckAccessPointViaUDDI]
HTTPWebNode.WebNodeOptions = []
Converter.Options = [soSendMultiRefObj, soTryAllSchema, soRootRefNodesToBody, soCacheMimeResponse, soUTF8EncodeXML]
Left = 48
Top = 8
end
end
wsdl importado:
unit cep;
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 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"[Gbl]
ArrayOfstring = array of string; { "urn:CEPService"[GblCplx] }
// ************************************************************************ //
// Namespace : urn:http://www.byjg.com.br
// soapAction: urn:CEPServiceAction
// transport : http://schemas.xmlsoap.org/soap/http
// style : rpc
// use : encoded
// binding : CEPServiceBinding
// service : CEPService
// port : CEPServicePort
// URL : http://www.byjg.com.br/site/webservice.php/ws/cep
// ************************************************************************ //
CEPServicePort = interface(IInvokable)
['{EC28595B-95D2-DE51-E5B1-57B81D4826D3}']
function obterVersao: string; stdcall;
function obterLogradouro(const cep: string): string; stdcall;
function obterLogradouroAuth(const cep: string; const usuario: string; const senha: string): string; stdcall;
function obterCEP(const logradouro: string; const localidade: string; const UF: string): ArrayOfstring; stdcall;
function obterCEPAuth(const logradouro: string; const localidade: string; const UF: string; const usuario: string; const senha: string): ArrayOfstring; stdcall;
end;
function GetCEPServicePort(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): CEPServicePort;
implementation
uses SysUtils;
function GetCEPServicePort(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): CEPServicePort;
const
defWSDL = 'http://www.byjg.com.br/site/webservice.php/ws/cep?WSDL';
defURL = 'http://www.byjg.com.br/site/webservice.php/ws/cep';
defSvc = 'CEPService';
defPrt = 'CEPServicePort';
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 CEPServicePort);
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
{ CEPServicePort }
InvRegistry.RegisterInterface(TypeInfo(CEPServicePort), 'urn:http://www.byjg.com.br', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(CEPServicePort), 'urn:CEPServiceAction');
RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfstring), 'urn:CEPService', 'ArrayOfstring');
end.
Elter Teodoro
Curtir tópico
+ 0
Responder
Posts
10/10/2013
Ricardo Rodrigues
Que erro aparece ?
Responder
Gostei + 0
10/10/2013
Elter Teodoro
Access violation at address 5b9B45D8,ACESSING ADDRES 0040014.
Usando depurador,notei que erro acontece na chamada da function obterVersao ou obterLogradouro
Usando depurador,notei que erro acontece na chamada da function obterVersao ou obterLogradouro
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)