Matthias Vandercleyen
asked on
Access a webservice trought dll with delphi
I'm making a dll in delphi 2010.
I'm trying to reach a webservice and execute a method on this webservice but i'm getting an access violation.
Is it possible to access a webservice from within a dll?
If so, how?
I'm trying to reach a webservice and execute a method on this webservice but i'm getting an access violation.
Is it possible to access a webservice from within a dll?
If so, how?
ASKER
In the dll i have the following export
exports
VatCodeChecker name 'VATCODECHECKER';
end.
wich refers to
function VatCodeChecker(value : checkVat ):checkVatResponse;
var
HTTPRIO1: THTTPRIO;
wsService : checkVatPortType;
begin
HTTPRIO1 := THTTPRIO.Create(nil);
HTTPRIO1.WSDLLocation := 'http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl';
HTTPRIO1.Service := 'checkVatService';
HTTPRIO1.Port := 'checkVatPort';
wsService := HTTPRIO1 as checkVatPortType;
Result := wsService.checkVat(value);
end;
and in my client, where i access the dll i have
try
Lib := loadLibrary('webService.dl l');
except on e:exception do
raise exception.Create('could not load webService.dll. ' + e.message);
end;
if Lib <> 0 then
begin
vcChecker := GetProcAddress(Lib, 'VATCODECHECKER');
Result := vcChecker(Value);
end;
exports
VatCodeChecker name 'VATCODECHECKER';
end.
wich refers to
function VatCodeChecker(value : checkVat ):checkVatResponse;
var
HTTPRIO1: THTTPRIO;
wsService : checkVatPortType;
begin
HTTPRIO1 := THTTPRIO.Create(nil);
HTTPRIO1.WSDLLocation := 'http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl';
HTTPRIO1.Service := 'checkVatService';
HTTPRIO1.Port := 'checkVatPort';
wsService := HTTPRIO1 as checkVatPortType;
Result := wsService.checkVat(value);
end;
and in my client, where i access the dll i have
try
Lib := loadLibrary('webService.dl
except on e:exception do
raise exception.Create('could not load webService.dll. ' + e.message);
end;
if Lib <> 0 then
begin
vcChecker := GetProcAddress(Lib, 'VATCODECHECKER');
Result := vcChecker(Value);
end;
ASKER
Also when i try to send an receive objects from the dll it works perfectly, only when i access a webservice, it crashes..
in this function :
function VatCodeChecker(value : checkVat ):checkVatResponse;
what is checkVatPortType ? The AS operator on
wsService := HTTPRIO1 as checkVatPortType;
has very little chance to work (will raise an exception) except if checkVatPortType is strictly equal to THTTPRIO
why don't you create directly HTTPPRIO as checkVatPortType ?
and What does checkVat method of wsService/checkVatPortType ?
function VatCodeChecker(value : checkVat ):checkVatResponse;
what is checkVatPortType ? The AS operator on
wsService := HTTPRIO1 as checkVatPortType;
has very little chance to work (will raise an exception) except if checkVatPortType is strictly equal to THTTPRIO
why don't you create directly HTTPPRIO as checkVatPortType ?
and What does checkVat method of wsService/checkVatPortType
function VatCodeChecker(value : checkVat ):checkVatResponse;
var
HTTPRIO1: checkVatPortType;
begin
HTTPRIO1 := checkVatPortType.Create(nil);
HTTPRIO1.WSDLLocation :=
'http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl';
HTTPRIO1.Service := 'checkVatService';
HTTPRIO1.Port := 'checkVatPort';
Result := HTTPRIO1.checkVat(value);
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
checkVatPort type is the import wsdl file from the internet ( http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl )
the checkVat method is a method wich is online and i can not access to view it's code.
When i run the exact same code in a normal windows form application, it works like a charm.
But when i try it from within a dll it gives access violations.
Are there any special things i need to add to the dll to make it access a webservice ?
the checkVat method is a method wich is online and i can not access to view it's code.
When i run the exact same code in a normal windows form application, it works like a charm.
But when i try it from within a dll it gives access violations.
Are there any special things i need to add to the dll to make it access a webservice ?
ASKER
not really solved, but probably just not possible
I see, HTTPRIO is a COM interface. I never used WebService so I didn't knew.
Still, I have used many COM interface, and it would seem that there is something missing in your dll :
CoInitialize / CoUninitialize . It is done automatically by Delphi for applications, but not for dll.
there is a link here that explains a complete solution
http://www.delphi3000.com/articles/article_2481.asp?SK=
Still, I have used many COM interface, and it would seem that there is something missing in your dll :
CoInitialize / CoUninitialize . It is done automatically by Delphi for applications, but not for dll.
there is a link here that explains a complete solution
http://www.delphi3000.com/articles/article_2481.asp?SK=
But since there is no application object and no automatic creation of the forms, you have to initialize those when your dll is loaded, or within your entry functions of your dll.
post your dll code, an we'll tell you what's needed if you forgot something