Discuss this help topic in SecureBlackbox Forum

SOAP: Create header or body of SOAP message

To create a Header element, that contains header information, and a Body element, that contains request or response information, you need to use TElXMLSOAPEnvelope.CreateHeader() and TElXMLSOAPEnvelope.CreateBody() methods respectively.

C#:


TElXMLDOMDocument XMLDocument = new TElXMLDOMDocument();
TElXMLSOAPMessage SOAPMessage = new TElXMLSOAPMessage(null);
try
{
	SOAPMessage.CreateEnvelope(XMLDocument, SOAP_v1_2);
	if (SOAPMessage.Envelope.Header == null)
		SOAPMessage.Envelope.CreateHeader();

    if (SOAPMessage.Envelope.Body == null)
		SOAPMessage.Envelope.CreateBody();

	// build message
	// ...
}
finally
{
	SOAPMessage.Dispose();
	XMLDocument.Dispose();
}

Delphi:

var
  XMLDocument : TElXMLDOMDocument;
  SOAPMessage : TElXMLSOAPMessage;
begin
  XMLDocument := TElXMLDOMDocument.Create;
  SOAPMessage := TElXMLSOAPMessage.Create(nil);
  try
    SOAPMessage.CreateEnvelope(XMLDocument, SOAP_v1_2);
    if not Assigned(SOAPMessage.Envelope.Header) then
      SOAPMessage.Envelope.CreateHeader();

    if not Assigned(SOAPMessage.Envelope.Body) then
      SOAPMessage.Envelope.CreateBody();
    // build message
  finally
    FreeAndNil(SOAPMessage);
    FreeAndNil(XMLDocument);
  end;
end;

To create an Envelope element, which identifies the XML document as a SOAP message, you need to use TElXMLSOAPMessage.CreateEnvelope() method, for example:

C#:


TElXMLDOMDocument XMLDocument = new TElXMLDOMDocument();
TElXMLSOAPMessage SOAPMessage = new TElXMLSOAPMessage(null);
try
{
	XMLDocument.LoadFromFile("filename.xml");
	SOAPMessage.LoadFromXML(XMLDocument);
	// process message
	...
}
finally
{
	SOAPMessage.Dispose();
	XMLDocument.Dispose();
}

Delphi:

var
  XMLDocument : TElXMLDOMDocument;
  SOAPMessage : TElXMLSOAPMessage;
begin
  XMLDocument := TElXMLDOMDocument.Create;
  SOAPMessage := TElXMLSOAPMessage.Create(nil);
  try
    XMLDocument.LoadFromFile('filename.xml');
    SOAPMessage.LoadFromXML(XMLDocument);
    // process message
  finally
    FreeAndNil(SOAPMessage);
    FreeAndNil(XMLDocument);
  end;
end;

How To articles about SOAP messages

Discuss this help topic in SecureBlackbox Forum