Fabio Gomes
Fabio Gomes

Reputation: 6022

Delphi wrapping TXMLData in SOAP request with <schema> tag

I'm sending a XML using TXMLData and Delphi is adding a tag in the request, my code is like this:

RequestData := TXMLData.Create;
RequestData.LoadFromXML('<MyXML>[contents here]</MyXML>');

MyService.ExecuteRequest(RequestData);

I used the OnBeforeExecute of the THTTPRIO to get the content of the Request and the content is wrapped in a tag, something like this:

<SOAP-ENV:Body>
    <schema xmlns="http://www.w3.org/2001/XMLSchema">
              <MyXML>
    </schema>
</SOAP-ENV:Body>

I can't figure out why this tag is being added. How can I prevent it from being added?

Also, I don't like the idea of editing the SOAPRequest in the OnBeforeExecute event to remove it without know with it is there.

Upvotes: 2

Views: 4288

Answers (3)

Fabio Gomes
Fabio Gomes

Reputation: 6022

Solved.

Delphi was mapping the webservice as:

RequestData = TXMLData;

MyService = interface(IInvokable)
  ['{5D2D1DD8-AE56-AD82-FC59-8669C576E1AF}']
  function ExecuteRequest(const RequestData: RequestData): RequestResult; stdcall;
end;

Changing:

RequestData = TXMLData;

to

RequestData = class(TXMLData);

Solved the issue.

Now delphi is using the "RequestData" as the top node of the XML in the Body of the request, instead of adding a schema tag.

Now the call is generating something like this:

<RequestData>[MyXML]</RequestData>

Which is what I need to send.

Upvotes: 1

mjn
mjn

Reputation: 36654

It looks like Delphi looks at the <MyXML> and thinks

"this piece of XML does not have an associated namespace, so I just throw it in the XMLSchema namespace - and hey!, this namespace is not yet in the namespaces of the SOAP message, so I will add it to make the SOAP server happy!"

  • note that in your example <MyXML> is not a well-formed XML document. It is only the opening 'tag'.

I don't know the TXMLData details but it might support namespaces. Maybe you can add a namespace declaration to the XML document, and then the SOAP request will look better.


SOAP request body example (from Wikipedia):

<s:Body>
    <m:TitleInDatabase xmlns:m="http://www.lecture-db.de/soap">
        DOM, SAX and SOAP
    </m:TitleInDatabase>
</s:Body>

This shows that a SOAP body can be a 'stand-alone' XML document with the namespace declaration in the root element (not a separate outer element as in your case).

Upvotes: 1

Chris Thornton
Chris Thornton

Reputation: 15817

It sounds like you have a non-compliant web service that you have to hit, but the SOAP library is getting in the way. So you may need to resort to the "brute force" approach of replacing the request in the OnBeforeExecute handler. Before doing that though, I'd try consuming the service WSDL with SoapUI. See if a SoapUI request is accepted by the service. If that doesn't work without severe editing of the request, then the above approach is justified.

Upvotes: 0

Related Questions