2

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.

Fabio Gomes
  • 5,914
  • 11
  • 61
  • 77
  • So, do you want to send raw data? – Leonardo Herrera Sep 06 '12 at 20:48
  • I don't know if this fits as "Raw", I'm loading a XML in the TXMLData and want this exactly XML to be in the Body of the Request. But Delphi is wrapping the contents of my data with this tag. – Fabio Gomes Sep 06 '12 at 20:49
  • Can you explain in more detail what you are trying to accomplish? Right now it is unclear why the `schema` element wrapper is a problem. – Jeroen Wiert Pluimers Sep 06 '12 at 21:49
  • I just need to send a xml to a webservice. But the way this webservice is implemented I need to send the exact xml or it will not validate. Right now this tag is making my calls to this webservice fail. I just need to send the xml I set in the TXMLData variable exactly as it is. – Fabio Gomes Sep 07 '12 at 00:39
  • There is no "just send the XML" in SOAP land. SOAP embeds XML, and you cannot have a fresh XML declaration inside an outer XML. So you need some for of wrapping, encapsulation, encoding or other. Post the WSDL: that should give at least a hint how the XML must be wrapped. – Jeroen Wiert Pluimers Sep 07 '12 at 06:58

3 Answers3

1

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).

mjn
  • 36,362
  • 28
  • 176
  • 378
  • +1, I think that your logic is correct. The problem is that delphi generated the type as RequestType = TXMLData and looked at my XML and said "Oh, this XML is not a TXMLData, let me correct it." so it added the schema tag. When I declared a new type inheriting from TXMLData it started generating the correct xml. – Fabio Gomes Sep 10 '12 at 16:44
1

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.

Fabio Gomes
  • 5,914
  • 11
  • 61
  • 77
0

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.

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62