Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8165139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:28:09+00:00 2026-06-06T19:28:09+00:00

I am using Delphi XE2 to communicate with a fairly large SOAP service. I’ve

  • 0

I am using Delphi XE2 to communicate with a fairly large SOAP service. I’ve successfully imported the wsdl and everything is working just fine. However, I find myself writing a lot of similar code. I would like to have a generic method that calls my web service. I also find it hard to multithread my code as it is now, since I have to write so much code for each type of call.

Being more of a weekend programmer I am far from mastering the in and outs of Delphi, but I think I at least have a fair understanding of RTTI, which I believe must be used to do what I want.

The web service has about 700 different methods and that is pretty much the problem. The code generated from the wsdl has methods as below:

function  addPhone(const Params: addPhone): addPhoneResponse; stdcall;
function  updatePhone(const Params: updatePhone): updatePhoneResponse; stdcall;
function  getPhone(const Params: getPhone): getPhoneResponse; stdcall;
function  removePhone(const Params: removePhone): removePhoneResponse; stdcall;
function  listPhone(const Params: listPhone): listPhoneResponse; stdcall;
function  addStuff(const Params: addStuff): addStuffResponse; stdcall;
function  updateStuff(const Params: updateStuff): updateStuffResponse; stdcall;
...
... about 700 more of the above

Basically, there is about 700 different type of things that can be handled, and there is add,update,get,remove and list-methods for them all. With each call, there is a corresponding class that is used as parameters to the SOAP request. There is also a corresponding class for the response as you can see above.

The classes would look something like (very simplified):

addStuff = class
  private
    FStuff: string;
  published
    property stuff: string  Index (IS_UNQL) read FStuff write FStuff;
  end;

So when I call the web service I do for example:

procedure CreateStuff;
var
    req:    addStuff;
    res:    addStuffResponse;
    soap:   MyWebServicePort;
begin
    // Use the function in the wsdl-generated code to create HTTPRIO
    soap := GetMyWebServicePort(false,'',nil);
    // Create Parameter Object
    req := addPhone.Create;
    req.stuff := 'test';
    // Send the SOAP Request
    res := soap.addStuff(req);
end;

(Yes, I know I should have try..finally and Free in there as well 🙂 )

Then, somewhere else in the code I need to call a different method:

procedure listStuff;
var
    req:    listStuff;
    res:    listStuffResponse;
    soap:   MyWebServicePort;
begin
    // Use the function in the wsdl-generated code to create HTTPRIO
    soap := GetMyWebServicePort(false,'',nil);
    // Create Parameter Object
    req := listPhone.Create;
    req.stuff := 'test2';
    // Send the SOAP Request
    res := soap.listStuff(req);
end;

Since I know that the parameter is always a class with a name that is equivalent of the method I call, I would like to be able to do something like the metacode below in order to dynamically invoking the call. I guess it requires some RTTI magic but I have’nt been able to find a way to do it:

procedure soapRequest(Param: Something; var Response: Something);
begin
  soap := GetMyWebServicePort(false,'',nil);
  Response := soap.DynamicInvoke(Param.ClassName, Param);
end

Then I could do something like:

soapRequest(VarOfTypeAddStuff,VarOfTypeAddStuffResponse)
soapRequest(VarOfTypeListStuff,VarOfTypeListStuffResponse)
...

Does anyone have an idea how my calls to the webservice can be simplified?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:28:10+00:00Added an answer on June 6, 2026 at 7:28 pm

    It’s really weird that I just a few hours after posting a question which I’ve been trying to solve myself for weeks all of a sudden just get solved by myself… I was inspired by looking around on SO, and I found this that helped me along the way: Delphi – Invoke Record method per name.

    My scenario i somewhat specific, since I am calling the methods with a parameter that has the same classname as the method itself. I also wrote simpler version that communicates with a public web service. If someone is interested, You can get the code for that one here: http://www.hook.se/delphi/SoapDynamicInvoke.zip. It’s kind of a useless example since doing dynamic method calls is only relevant when the web service has a lot of different methods. Nevertheless, it might be interesting to somebody 🙂

    Below is how I solved this for my web service. As said, it’s quite specific and the code could be made more generic but this works for me.

    This method is called with a TRemotable object, and then the web service is called with the method with the same name as the class name of the object.

    function soapRequest(Param: TRemotable): TValue;
    var
      soap: AXLPort;
      C: TRttiContext;
      T: TRttiType;
      M: TRttiMethod;
      SoapParam: TArray<TValue>;
      TVres: TValue;
      soap: MyWebServicePort;
    begin
      // Use the function in the wsdl-generated code to create HTTPRIO
      soap := GetMyWebServicePort(false,'',nil);  C := TRttiContext.Create;
      T := C.FindType('MyWebService.MyWebServicePort');
      M := T.GetMethod(Param.ClassName);
      SetLength(SoapParam,1);
      SoapParam[0] := TValue.From(Param);
      TVres := M.Invoke(TValue.From<IInterface>(soap), SoapParam);
      Result := TVres;
    end;
    

    And to use the function above:

    procedure DoSomeSoapCalls(Sender: TObject);
    var
      req1: getStuff
      res1: getStuffResponse;
      req2: addStuff;
      res2: addStuffResponse;
      res:  TValue;
    begin
      //Request #1
      req1 := getStuff.Create;
      req1.stuffToGet := 'abc';
      try
        res := soapRequest(req1);
        res1 := getStuffResponse(res.AsObject);
      finally
        req1.Free;
      end;
      Writeln(res1.someproperty);
      FreeAndNil(res1);
    
      //Request #2
      req2 := addStuff.Create;
      req2.StuffToAdd := 'cde';
      try
        res := soapRequest(req2);
        res2 := addStuffResponse(res.AsObject);
      finally
        req2.Free;
      end;
      Writeln(res2.result);
      FreeAndNil(res2);
    end;
    

    There is a bit of typecasting necessary, but in my case I think that I’ll be pretty safe with that. Does anyone have any other comments/suggestions regarding this? I mean, this works, but there is probably ways to enhance it.

    Cheers,

    Dan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Delphi XE2 on Win 7 64 bit creating a 32 bit app... In
I have developed an database application with Delphi XE2 using an Access DB, now
I am having problems using SOAP in XE/XE2 from a thread. (I didn't test
I am using Delphi XE2 with help installed. I want to see the hints
I am trying to write an iPhone app using Delphi XE2 / FireMonkey and
I just noticed that in some of the new VCL styles in Delphi XE2,
Using Delphi XE2 update 3 or update 4 on Win7 64 bit. Calling enumwindows
I am using Delphi XE2 to write a VCL win32 application. Delphi XE2 support
I'm using Delphi XE2 and a TSQLQuery object. It works the first time that
I use ActivateKeyboardLayout(HKL_NEXT, KLF_ACTIVATE); to load Persian keyboard layout using Delphi XE2, But sometimes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.