Repository navigation
SOAP Headers
SOAP Headers are also inheriting from TRemotable but you need to use TSOAPHeader as a base class, which is located in Soap.InvokeRegistry.
From there on it's no different than creating other 'remotable' classes:
TMySoapHeader = class(TSOAPHeader)
private
FSomeData: string;
published
property SomeData: string read FSomeData write FSomeData;
end;One of the most commonly used headers is the WS-Security header (https://en.wikipedia.org/wiki/WS-Security). SW-Sec has multiple different implementations, depending on which information to need/want to send.
I've created different versions for the Username/password implementation:
- WSSecurity200306.pas
- WSSecurity200401.pas
SOAP Headers are NOT automatically created by the WDSL importer of Delphi. Therefore you need to manually create then AND then know how to attach them to your request before sending the request.
To attach a SOAP header you need to access the SOAP header interface ISOAPHeaders which is also located in Soap.InvokeRegistry.
To add a header use the folowing code:
aHeader := TMySoapHeader.Create;
aHeader.SomeData := 'data';
(Webservice as ISOAPHeaders).Send(aHeader);
resp := Webservice.DoSomeRequest(...);Please note, just like regular remotable you need to manage the lifetime of the SOAP Header. When needing to make multiple requests using the same header, you can keep the header object and attach it before sending each request.
As an alternative to using the header only for one request, you can instruct the service to 'own' the header and let it free the header once the request has been made:
(Webservice as ISOAPHeaders).OwnsSentHeaders := True;