title: Sending SOAP headers with httprio
body: <p>I have a C# application which I am struggling to emulate in Delphi because the authentication is failing.  I believe this is down to an incorrect authentication header.  The (relevant, working) C# code is like so:</p>
  
  <pre><code>public class CustomMessageInspector : IClientMessageInspector
  {
      public CustomMessageInspector()
      { }
  
      public void AfterReceiveReply(ref Message reply, object correlationState)
      { }
  
      public object BeforeSendRequest(ref Message request, IClientChannel channel)
      {
          AddHeaderToMessage(ref request, "Authentication", Constants.AUTH_VALUE);
          AddHeaderToMessage(ref request, "Application", Constants.APP_NAME);
  
          return null;
      }
  
      private void AddHeaderToMessage(ref Message message, string name, string value)
      {
          var header = new MessageHeader&lt;string&gt;(value);
  
          var untyped = header.GetUntypedHeader(name, Constants.NAME_SPACE);
  
          message.Headers.Add(untyped);
      }
  } 
  </code></pre>
  
  <p>My Delphi equivalent looks like this:</p>
  
  <pre><code>unit Main;
  
  interface
  
  uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Soap.InvokeRegistry, Vcl.StdCtrls,
    Soap.Rio, Soap.SOAPHTTPClient, SOAPHTTPTrans,
    MembershipService;
  
  type
    TStringHeader = class(TSOAPHeader)
    private
      FVal : string;
    public
      property Value : string read FVal write FVal;
    end;
  
    AuthHeader = class(TStringHeader);
    AppHeader  = class(TStringHeader);
  
    TForm3 = class(TForm)
      GetUserButton: TButton;
      HTTPRIO1: THTTPRIO;
      HttpRio: THTTPRIO;
      procedure GetUserButtonClick(Sender: TObject);
      procedure HttpRioHTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp; Data: Pointer);
    private
      _currUser : User2;
      function svc: IMembershipService;
    public
    end;
  
  var
    Form3: TForm3;
  
  implementation
  
  {$R *.dfm}
  
  procedure TForm3.HttpRioHTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp;  Data: Pointer);
  var
    Header : TStringHeader;
  begin
    Header := AuthHeader.Create();
    try
      Header.Value := Constants.AUTH_VALUE;
      (svc as ISOAPHeaders).Send(Header);
    finally
      FreeAndNil(Header);
    end;
  
    Header := AppHeader.Create();
    try
      Header.Value := Constants.APP_NAME;
      (svc as ISOAPHeaders).Send(Header);
    finally
      FreeAndNil(Header);
    end;
  end;
  
  function TForm3.svc : IMembershipService;
  begin
    Result := HttpRio as IMembershipService;
  end;
  
  
  initialization
    InvRegistry.RegisterHeaderClass(TypeInfo(IMembershipService), AuthHeader, 'Authentication', Constants.NAME_SPACE);
  
    InvRegistry.RegisterHeaderClass(TypeInfo(IMembershipService), AppHeader, 'Application', Constants.NAME_SPACE);
  </code></pre>
  
  <p>end.</p>
  
  <p>I believe it may relate to the 'Namespace' value, but am not sure. Can anyone advise? </p>