Access a webservice trought dll with delphi

gonniegijsen
gonniegijsen used Ask the Experts™
on
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?


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Emmanuel PASQUIERFreelance Project Manager
Top Expert 2010

Commented:
you can do anything from a dll. You can have forms, datamodules, TCP/IP components or whatever you need for your webservice.

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

Author

Commented:
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.dll');
    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;


Author

Commented:
Also when i try to send an receive objects from the dll it works perfectly, only when i access a webservice, it crashes..
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Emmanuel PASQUIERFreelance Project Manager
Top Expert 2010

Commented:
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;
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;

Open in new window

Freelance Project Manager
Top Expert 2010
Commented:
other than that, it looks good. maybe you could check also if you found the function in the dll :
   if Lib <> 0 then
     begin
       vcChecker := GetProcAddress(Lib, 'VATCODECHECKER');
       if Not Assigned(vcChecker) 
        Then Raise Exception.Create('VATCODECHECKER not found in dll')
        Else Result := vcChecker(Value);
     end;

Open in new window

Author

Commented:
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 ?


Author

Commented:
not really solved, but probably just not possible
Emmanuel PASQUIERFreelance Project Manager
Top Expert 2010

Commented:
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=

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial