Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Consumir webservice manda variables null (https://www.clubdelphi.com/foros/showthread.php?t=70471)

ocram 22-10-2010 17:38:32

Consumir webservice manda variables null
 
Buenos dias.

Tengo un WebService hecho en .net al cual le paso un numero de habitacion y resort y me devuelve un xml con informacion del huesped, cuando entro directamente desde el explorador de internet y le pongo manualmente la variables funciona perfectamente el problema es que quiero consumir este webservice desde delphi 6 y al momento de ejecutarlo si consume el webservice pero el problema es que le envia null en las variables.

Aqui les dejo el codigo que se creó automaticamente mediante el wizard de delphi:

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://localhost/webservice/PMSWebService.asmx?WSDL
// Encoding : utf-8
// Version : 1.0
// (21/10/2010 10:28:12 a.m. - $Revision: 1.9.1.0.1.0.1.9 $)
// ************************************************************************ //

unit PMSWebService;

interface

uses InvokeRegistry, 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.
// ************************************************************************ //
// !:int - "http://www.w3.org/2001/XMLSchema"
// !:string - "http://www.w3.org/2001/XMLSchema"


// ************************************************************************ //
// Namespace : http://tempuri.org/
// soapAction: http://tempuri.org/DatosHuesped
// transport : http://schemas.xmlsoap.org/soap/http
// binding : Service1Soap
// service : Service1
// port : Service1Soap
// URL : http://localhost/webservice/PMSWebService.asmx
// ************************************************************************ //
Service1Soap = interface(IInvokable)
['{CFE467D4-A39E-2BD2-5836-7685A9E27F8D}']
function DatosHuesped(const idResort: Integer; const Habitacion: String): String; stdcall;
end;

function GetService1Soap(UseWSDL: Boolean=System.False; Addr: string=''): Service1Soap;


implementation
uses SOAPHTTPClient;

function GetService1Soap(UseWSDL: Boolean; Addr: string): Service1Soap;
const
defWSDL = 'http://localhost/webservice/PMSWebService.asmx?WSDL';
defURL = 'http://localhost/webservice/PMSWebService.asmx';
defSvc = 'Service1';
defPrt = 'Service1Soap';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
RIO := THTTPRIO.Create(nil);
try
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
Result := (RIO as Service1Soap);
finally
if Result = nil then
RIO.Free;
end;
end;


initialization
InvRegistry.RegisterInterface(TypeInfo(Service1Soap), 'http://tempuri.org/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Service1Soap), 'http://tempuri.org/DatosHuesped');

end.



Y AQUI LO QUE HAGO YO PARA TRATAR DE CONSUMIR EL WEB SERVICE, ES UNA FORMA DONDE AGREGO UN HTTPRIO 2 EDIT (UNO PARA # DE RESORT Y OTRO PARA # NUMERO DE HABITACION) Y UN MEMO QUE ES DONDE QUIERO PONER EL XML DEVUELTO.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Rio, SOAPHTTPClient, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
Button1: TButton;
HTTPRIO1: THTTPRIO;
HTTPRIO2: THTTPRIO;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

USES PMSWebService, ReservationsConsumer;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
res: String;
begin
Memo1.Lines.Text:= (HTTPRIO1 as Service1SoaP).DatosHuesped(StrToInt(Edit1.Text), Edit2.Text);
end;

end.


ENTONCES ESTO SI CONSUME EL WEBSERVICE PERO LAS VARIABLES DE LA FUNCION DATOSHUESPED LOS MANDA COMO NULL

ALGUNA IDEA DE EN QUE ESTOY FALLANDO?


GRACIAS

charlatan 29-10-2010 19:41:32

eso pasa es una pulga del importer, en el archivo generado por el importer nada mas te vas a la parte de inicializacion en la parte de abajo del archivo, en la cual existe una linea parecida a esta.

InvRegistry.RegisterInvokeOptions(TypeInfo(xxx), ioDocument)

esa linea la pones de primera despues del "initialization" y ya funciona
en tu caso no veo esa linea
nada mas agregala en el inicio y remplaza xxx por la interface
queria algo asi

initialization
InvRegistry.RegisterInvokeOptions(TypeInfo(Service1Soap), ioDocument); ///ESTA LINEA AGREGALA
InvRegistry.RegisterInterface(TypeInfo(Service1Soap), URL, 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Service1Soap), OTROURL);

end.

no me deja poner url asi q los cambie para q me dejara postear


La franja horaria es GMT +2. Ahora son las 17:26:32.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi