How to send a SOAP WSDL request

The code applies to Clever Internet Suite v9.4 and higher.
 
procedure TForm1.SendSoapWsdl;
var
  request: TclSoapMessage;
  http: TclHttp;
  response: string;
  dom: IXMLDomDocument;
  node: IXMLDOMNode;
begin
  request := TclSoapMessage.Create(nil);
  http := TclHttp.Create(nil);
  responseSoap := TclSoapMessage.Create(nil);
  try
    request.BuildSoapWSDL(
      'http-method-uri',
      'remote-method-name',
      ['parameter1', 'parameter2'], ['value1', 'value2']);

    response := http.Post('http...', request);

    //You can analyze the response XML directly:
    dom := CoDOMDocument.Create();
    dom.loadXML(WideString(response));
    node := dom.selectSingleNode('//result');

    //or load the response to a TclSoapMessage instance
    //This may be helpful if a response contains attachments, and you need to extract them.
    //See the "How to create/parse SOAP MTOM/XOP, XML, and binary attachments" article.

  finally
    http.Free();
    request.Free();
  end;
end;

Add Feedback