RAD Studio
ContentsIndex
PreviousUpNext
Processing Headers in Client Applications

If the Web Service application you are calling expects your client to include any headers in its requests or if its response messages include special headers, your client application needs the definitions of the header classes that correspond to these headers. When you import a WSDL document that describes the Web Service application, the importer automatically generates code to declare these header classes and register them with the remotable type registry. If the server is written in Delphi, you can use the same units that the server application uses to define and register these header classes instead of the files generated by importing a WSDL file. Be sure that the unit uses the same namespace URI and SOAPAction header when it registers invokable interfaces. These values can be explicitly specified in the code that registers the interfaces, or it can be automatically generated. If it is automatically generated, the unit that defines the interfaces must have the same name in both client and server, and both client and server must define the global AppSpacePrefix variable to have the same value.

Note: For more information about header classes, see Defining and using SOAP headers.
As with a server, client applications use the ISOAPHeaders interface to access incoming headers and add outgoing headers. The remote interfaced object that you use to call invokable interfaces implements the ISOAPHeaders interface. However, you can't obtain an ISOAPHeaders interface directly from the remote interfaced object. This is because when you try to obtain an interface directly from a remote interfaced object, it generates an in-memory vtable, assuming that the interface is an invokable interface. Thus, you must obtain the ISOAPHeaders interface from the invokable interface rather than from the remote interfaced object:

var
  Service: IMyService;
  Hdr: TAuthHeader;
  Val: Double;
begin
  Service := HTTPRIO1 as IService;
  Hdr := TAUthHeader.Create;
  try
    Hdr.Name := "Frank Borland";
    Hdr.Password := "SuperDelphi";
    (Service as ISOAPHeaders).Send(Hdr); { add the header to outgoing message }
    Val := Service.GetQuote("BORL"); { invoke the service }
  finally
    Hdr.Free;
  end;
end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!