Send simple strings in SOAP Header in Delphi

前端 未结 3 1611
灰色年华
灰色年华 2021-02-08 01:49

I need to send something like this:

   
      admin
      secret         


        
3条回答
  •  佛祖请我去吃肉
    2021-02-08 02:16

    Solution:

    It wasn't much obvious, but I just had to add the IS_TEXT value to the Index and declare a new TSOAPHeader descendant, the solution was like this:

    const
      IS_TEXT = $0020;
    
    type
      TSimpleHeader = class(TSOAPHeader)
      private
        FValue: string;
      published
        property Value: string Index (IS_TEXT) read FValue write FValue;
      end;
    
      userName = class(TSimpleHeader);
    

    Then register this header:

    InvRegistry.RegisterHeaderClass(TypeInfo(WsService), userName, 'userName', 'http://localhost/path/to/services');
    

    And send the Header manually:

        User := userName.Create;
        User.Value := 'username';
    
        (WS as ISOAPHeaders).Send(User);
    

    Basically, the IS_TEXT value in the Index prevents Delphi from creating a userName tag and a Value tag inside it. It just places the string of the Value property inside the userName tag.

    It's sad that the Index keywork is used for something so not obvious, also the documentation about it is difficult to find and hard to understand:

    The AS_ATTRIBUTE feature has been deprecated. It still works for legacy code, but the preferred approach is to use the index value of a property. The index property allows you to specify whether a property is an attribute, an unbounded element, an optional element, a text value, or can have a value of NULL.

    Source: http://docwiki.embarcadero.com/RADStudio/XE3/en/Using_Remotable_Objects

提交回复
热议问题