开发者

Consume WCF from a Delphi client (arrays and inheritance)

I've prototyped a WCF service that has an operation that receives an array of objects as single parameter. The trouble is, each object inherits f开发者_Python百科rom a base class (called Message) and the order of them isn't know up-front. At first, what WCF receives (incorrectly) is an array of Message elements, instead of the correct type, derived from Message.

After some effort, I was able to call this service from Delphi 6.02. I've used WSDL importer to create the basic client and hand-edited the source to correct some incompatibilities with the Delphi SOAP interpretation. Basically, I do some tweaks in the OnBeforeExecute event, like this:

SOAPRequest := StringReplace(SOAPRequest, '<item ', '<Message ', [rfReplaceAll]);

The above code corrects the way Delphi passes array elements. I learned it here Array_Of_Int in SOAP client.

Then, each object is encoded as a Message, but an attribute points to its runtime type:

<Message xsi:type="Authenticate"> <!-- I need to get this, exactly, types can vary -->

The problem is, here we go, I have other kinds of arrays. Then, an occurrence of "item" could be replaced by Attachment, or Address. If I mark the class as ioDocument, then I get the base class as tag-name but lose the correct type via attribute.

Any ideas to handle it? An other SOAP library I could use, perhaps? Or can .NET understand the "item" encoding?

Thank you.


I managed to make it work, but had to modify Delphi Sources like this:

{OPToSOAPDomConv.pas, around line 3001}
procedure TSOAPDomConv.SetNodeType(RootNode, InstNode: IXMLNode; const ElemURI,
  TypeName: InvString);
var
  Pre, AttNodePre: InvString;
begin
  if not (soSendUntyped in Options) /*and not (soDocument in Options)*/ then
...

This way, an object is guaranted to export the actual type:

<Message xsi:type="Authenticate"> <!-- I need to get this, exactly, types can vary -->
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜