问题
I have a pretty abnormal(IMHO) error that it's being raised whenever I try do a request to a SOAP service:
Unmarshalling Error: unexpected element (uri:"http://www.domain.com/ws/servicename/", local:"dummyArg"). Expected elements are <{}dummyArg>
The method that I'm calling has is defined as:
function GetData(const dummyArg: WideString): Array_Of_Data; stdcall;
I have little experience with SOAP therefore I'm this [ ] close to lose my mind, I couldn't find any useful information on this. Feel free to ask any question that might speed up the process in finding the issue.
EDIT: I'm using Delphi 2010, and I've called the method like so:
GetData(EmptyStr);
, GetData('null');
and GetData('{}');
Thank you for your time.
回答1:
I've managed to find a clean fix to my issue, just replace the invoke option in the initialization section of the unit from ioDocument to ioHasNamespace or ioHasAllSOAPActions and the SOAP request will be generated correctly, example:
InvRegistry.RegisterInvokeOptions(TypeInfo(YourSoapInterface), ioDocument);
change to
InvRegistry.RegisterInvokeOptions(TypeInfo(YourSoapInterface), ioHasNamespace);
or
InvRegistry.RegisterInvokeOptions(TypeInfo(YourSoapInterface), ioHasAllSOAPActions);
This is the cleanest fix I could find for this issue.
回答2:
I assume the exception raised is of type ERemotableException (http://docwiki.embarcadero.com/VCL/en/InvokeRegistry.ERemotableException) right? This means that the Service did not like the request and sent back a Fault; the SOAP runtime, upon seeing the fault, raises a local exception with the message received.
Based on what the Service said,
Unmarshalling Error: unexpected element (uri:"http://www.domain.com/ws/servicename/", local:"dummyArg"). Expected elements are <{}dummyArg>
...I assume that the client generated an invalid XML request. It's possible that the Service requires support some XML/SOAP construct that 2010 did not support. For example, the D2010 importer/runtime assumed that the namespace request/response of each operation match that the interface/porttype. That's typically the case but not always. In Delphi XE this was addressed by adding support to register the namespace of the request/response, when necessary. And it is possible to retrofit these fixes in the earlier runtime: the issue is first to assess the problem.
Could you post a link to the WSDL of the Service? It's much easier to investigate these issues with access to the WSDL. Thank you.
Cheers,
Bruneau
回答3:
I had the same problem. And my decision differs from those. To solve this problem you should to set options correctly in WSDL Importer Dialog in Delphi. In my case i've selected 2 additional options:
- "Map pure collections to wrapper class types (-Ok)
- Map String to WideString (-Ow)
Rebuild the application and error disappeared. Hope this will help somebody.
来源:https://stackoverflow.com/questions/4884560/unmarshalling-error