# Using soap header to authenticate user in stateless mode

**URL:** https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559
**Category:** Remoting SDK
**Tags:** delphi
**Created:** [May 28, 2016, 1:33am UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559 "2016-05-28T01:33:49Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Bob\_Murdoch](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@Bob\_Murdoch](https://talk.remobjects.com/u/Bob_Murdoch)
#### Post date: [May 28, 2016, 1:33am UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/1 "2016-05-28T01:33:49Z")

</div>

Using Delphi with the latest ROSDK:

We are implementing a service that will require the client to send user id and password in the soap header on each method call.

I see that TROSoapMessage has a HeaderNode property, but which event would I use to evaluate that header?

Thank you.

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [May 30, 2016, 8:34am UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/2 "2016-05-30T08:34:59Z")

</div>

you can use [OnGetDispatchInfo](https://docs.remotingsdk.com/API/Delphi/TRORemoteDataModule_Class/#OnGetDispatchInfo) event like

```auto
procedure TMegaDemoService.RORemoteDataModuleGetDispatchInfo(const aTransport: IROTransport;
  const aMessage: IROMessage);
var
  k: IXMLNode;
  soap: IROSOAPMEssage;
begin
  if Supports(aMessage, IROSOAPMEssage, soap) then begin
    k := soap.HeaderNode;
    // do something
  end;
end;

```

---

<div class="post-metadata">

### Author: ![Bob\_Murdoch](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@Bob\_Murdoch](https://talk.remobjects.com/u/Bob_Murdoch)
#### Post date: [June 3, 2016, 8:30pm UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/3 "2016-06-03T20:30:48Z")

</div>

Thanks Evgeny - that works perfectly.

However, how can we update the WSDL in our server so that the client that implements the WSDL is aware that the username and password are required in the header?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [June 6, 2016, 8:44am UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/4 "2016-06-06T08:44:05Z")

</div>

so do you want to send username&password at each client request?  
we send `ROClientIDHeader` tag that specifies client session if on server-side by default in ROD

---

<div class="post-metadata">

### Author: ![Bob\_Murdoch](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@Bob\_Murdoch](https://talk.remobjects.com/u/Bob_Murdoch)
#### Post date: [June 6, 2016, 1:11pm UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/5 "2016-06-06T13:11:35Z")

</div>

Yes, the client would send user-id/password on each request in the header. The customer of this API cannot handle session tracking on their side, so they don’t want/can’t use the ROClientIDHeader.

The service is working for them if they manually modify the header on their side, but they would like the .Net importer to parse the WSDL and create the header class for them.

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [June 6, 2016, 1:27pm UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/6 "2016-06-06T13:27:36Z")

</div>

pls read this article - [Tip: Implement implicit and explicit SOAP headers](http://www.ibm.com/developerworks/library/ws-tip-headers/)

---

<div class="post-metadata">

### Author: ![Bob\_Murdoch](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@Bob\_Murdoch](https://talk.remobjects.com/u/Bob_Murdoch)
#### Post date: [June 7, 2016, 12:54pm UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/7 "2016-06-07T12:54:07Z")

</div>

Thank you Evgeny, that is certainly an interesting article.

Is there an event in RemObjects that allows us to inject these implicit or explicit headers? I haven’t had any luck finding one yet.

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [June 7, 2016, 12:57pm UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/8 "2016-06-07T12:57:00Z")

</div>

you can use [OnEnvelopeComplete](https://docs.remotingsdk.com/API/Delphi/TROSOAPMessage_Class/#OnEnvelopeComplete) event of TROSOAPMessage

---

<div class="post-metadata">

### Author: ![JA](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@JA](https://talk.remobjects.com/u/JA)
#### Post date: [June 7, 2016, 3:12pm UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/9 "2016-06-07T15:12:15Z")

</div>

We have already tried the suggested solution of using OnEnvelopeComplete to adjust the outgoing WSDL. The problem is OnEnvelopeComplete doesn’t fire on the server when a client requests the WSDL. After looking through the TROSOAPMessage object, it looks like the GetModuleInfo method is responsible for converting the RODL spec into a WSDL spec. We haven’t been to find an event that lets us manipulate the WSDL content before it is sent back in a response.

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [June 8, 2016, 8:15am UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/10 "2016-06-08T08:15:53Z")

</div>

this is a bit tricky.  
declare this class near to your server:

```auto
TMySOAPMessage = class(TROSOAPMessage)
protected
  procedure GetModuleInfo(aStream : TStream; const aTransport : IROTransport; var aFormat : TDataFormat); override;
end;

procedure TMySOAPMessage.GetModuleInfo(aStream: TStream; const aTransport: IROTransport; var aFormat: TDataFormat);
begin
  inherited GetModuleInfo(aStream, aTransport, aFormat);
  // modify content of stream 
end;

```

register it instead of std TROSOAPMessage:

```auto
procedure TServerForm.FormCreate(Sender: TObject);
var
  fdisp : TROHTTPDispatcher;
begin
  fdisp := TROHTTPDispatcher(ROServer.Dispatchers.Add);
  fdisp.Message := TMySOAPMessage.Create(Self);
  fdisp.PathInfo := '/soap';
  ROServer.Active := true;
end;

```

---

<div class="post-metadata">

### Author: ![JA](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@JA](https://talk.remobjects.com/u/JA)
#### Post date: [June 10, 2016, 10:29am UTC](https://talk.remobjects.com/t/using-soap-header-to-authenticate-user-in-stateless-mode/9559/11 "2016-06-10T10:29:29Z")

</div>

Thank you. Your information was very useful, and helped us add the desired extra WSDL details.
