Discuss this help topic in SecureBlackbox Forum

SOAP: Create custom complex parameter class for SOAP message

To replicate your complex parameter structure and manage a complex parameter you can create a descendant of TElXMLSOAPCompoundParameter class.

To add the complex parameters you would need to use TElXMLSOAPClient.AddCompoundParameter() method and then add scalar values and/or compound values into it.

C#:


public class ComplexParamClass1: TElXMLSOAPCompoundParameter
{
	private ComplexParamClass2 FComplexParam2;

	public ComplexParamClass1()
	{
		ParameterName = "ComplexParam1";
		ParameterNamespaceURI = "http://...";

		// adding parameters
		FComplexParam2 = new ComplexParamClass2();
		Add(FComplexParam2);
	}

    public ComplexParamClass2 ComplexParam2
	{
		get { return FComplexParam2; }
	}
 }

public class ComplexParamClass2: TElXMLSOAPCompoundParameter
{
	private TElXMLSOAPStringParameter FStringParam;

	public ComplexParamClass2()
	{
		ParameterName = "ComplexParam2";
		ParameterNamespaceURI := "http://...";

		// adding parameters
		FStringParam = new TElXMLSOAPStringParameter();
		FStringParam.ParameterName = "StringParam";
		FStringParam.ParameterNamespaceURI = "http://...";
		Add(FStringParam);
	}

	public StringParam
	{
		get { return FStringParam.Value; }
		set { FStringParam.Value = value; }
	}
}

Delphi:

type
  TComplexParam2 = class;

  TComplexParam1 = class(TElXMLSOAPCompoundParameter)
  private
    FComplexParam2 : TComplexParam2;
  public
    constructor Create;

    property ComplexParam2 : TComplexParam2 read FComplexParam2;
  end;

  TComplexParam2 = class (TElXMLSOAPCompoundParameter)
  private
    FStringParam : TElXMLSOAPStringParameter;

    function GetStringParam() : string;
    procedure SetStringParam(const Value : string);
  public
    constructor Create;

    property StringParam : string read GetStringParam write SetStringParam;
  end;

constructor TComplexParam1.Create;
begin
  inherited;
  ParameterName := 'ComplexParam1';
  ParameterNamespaceURI := 'http://...';
  // adding parameters
  FComplexParam2 := TComplexParam2.Create;
  Add(FComplexParam2);
end;

constructor TComplexParam2.Create;
begin
  inherited;
  ParameterName := 'ComplexParam2';
  ParameterNamespaceURI := 'http://...';
  // adding parameters
  FStringParam := TElXMLSOAPStringParameter.Create;
  FStringParam.ParameterName := 'StringParam';
  FStringParam.ParameterNamespaceURI := 'http://...';
  Add(FStringParam);
end;

function TComplexParam2.GetStringParam() : string;
begin
  Result := FStringParam.Value;
end;

procedure TComplexParam2.SetStringParam(const Value : string);
begin
  FStringParam.Value := Value;
end;

Then to add and initialize this parameter use this code:

C#:


ComplexParamClass1 param = new ComplexParamClass1();
SOAPClient.AddParameter(param);
param.ComplexParam2.StringParam = "text value";

Delphi:

param := TComplexParam1.Create;
SOAPClient.AddParameter(param);
param.ComplexParam2.StringParam := 'text value';

Then, if you want the component to automatically parse such parameters on response (which can be accessed using TElXMLSOAPClient.ResponseParameters/ResponseParameterCount properties), you need to register your compound parameter class:

C#:


SBXMLSOAPClient.__Global.SOAPParametersManager.Add("ComplexParam1", "http://...", ComplexParamClass1);

Delphi:

SOAPParametersManager.Add('ComplexParam1', 'http://...', TComplexParam1);

How To articles about SOAP client

Discuss this help topic in SecureBlackbox Forum