Delphi wrapping TXMLData in SOAP request with <schema> tag

久未见 提交于 2019-12-12 10:08:20

问题


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.


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/12307943/delphi-wrapping-txmldata-in-soap-request-with-schema-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!