Board index » delphi » Nested TXSDateTime fields in Win32 SOAP Servers
Bob Swart
Delphi Developer |
Nested TXSDateTime fields in Win32 SOAP Servers2006-10-15 05:56:10 PM delphi13 Hi All, Some time ago, I detected a problem with nested TXSDateTime fields (inside structures) and Win32 SOAP Servers, where .NET clients would not be able to recognise the values for these parameters. I have now been able to diagnose this (the generated SOAP response differs from what is expected) and solve it (by modifying the SOAP response manually). To reproduce the problem, create a new Win32 SOAP Server Application (using Delphi 2006, although older versions of Delphi will show the same behaviour), and for the SOAP interface use the sample methods, which include echo methods including an echoMyEmployee. Extend the MyEmployee class to include a field of type TXSDateTime, as follows: TMyEmployee = class(TRemotable) private FLastName: AnsiString; FFirstName: AnsiString; FSalary: Double; FBirthdate: TXSDateTime; published property LastName: AnsiString read FLastName write FLastName; property FirstName: AnsiString read FFirstName write FFirstName; property Salary: Double read FSalary write FSalary; property Birthdate: TXSDateTime read FBirthdate write FBirthdate; end; And implement the echoMyEmployee as follows: function TEcho.echoMyEmployee(const Value: TMyEmployee): TMyEmployee; stdcall; begin Result := TMyEmployee.Create; Result.LastName := Value.LastName; Result.FirstName := Value.FirstName; Result.Salary := Value.Salary; Result.Birthdate := Value.Birthdate; end; The incoming SOAP request at this Win32 is as follows: == Before Dispatch == <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="schemas.xmlsoap.org/soap/encoding/" xmlns:tns="tempuri.org/" xmlns:types="tempuri.org/encodedTypes" xmlns:xsi="www.w3.org/2001/XMLSchema-instance" xmlns:xsd="www.w3.org/2001/XMLSchema"><soap:Body soap:encodingStyle="schemas.xmlsoap.org/soap/encoding/"><q1:echoMyEmployee xmlns:q1="urn:EchoIntf-IEcho"><Value href="#id1" /></q1:echoMyEmployee><q2:TMyEmployee id="id1" xsi:type="q2:TMyEmployee" xmlns:q2="urn:EchoIntf"><LastName xsi:type="xsd:string">Swart</LastName><FirstName xsi:type="xsd:string">Bob</FirstName><Salary xsi:type="xsd:double">4242</Salary><Birthdate xsi:type="xsd:dateTime">2006-10-14T20:34:11.6250000+02:00</Birthdate></q2:TMyEmployee></soap:Body></soap:Envelope> The outgoing SOAP response of the echoMyEmployee method is as follows: == After Dispatch == <?xml version="1.0"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="www.w3.org/2001/XMLSchema" xmlns:xsi="www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body SOAP-ENV:encodingStyle="schemas.xmlsoap.org/soap/encoding/" xmlns:NS2="urn:EchoIntf"> <NS1:echoMyEmployeeResponse xmlns:NS1="urn:EchoIntf-IEcho"> <return href="#1"/> </NS1:echoMyEmployeeResponse> <NS2:TMyEmployee id="1" xsi:type="NS2:TMyEmployee"> <LastName xsi:type="xsd:string">Swart</LastName> <FirstName xsi:type="xsd:string">Bob</FirstName> <Salary xsi:type="xsd:double">4242</Salary> <xsd:Birthdate xsi:type="xsd:dateTime">2006-10-14T20:34:11.6250000+02:00</xsd:Birthdate> </NS2:TMyEmployee> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Note the xsd:Birthdate instead of simply Birthdate. Delphi Win32 clients won't mind, but .NET clients will show the value of Birthdate as 0 (or 01-01-01 00:00:00 actually). A way to fix this, and allow both Win32 and .NET clients to recoginise the value of the Birthdate field was to remove the xsd: prefix from the xsd:Birthdate nodes. This results in the following SOAP response, which is handled just fine: <?xml version="1.0"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="www.w3.org/2001/XMLSchema" xmlns:xsi="www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body SOAP-ENV:encodingStyle="schemas.xmlsoap.org/soap/encoding/" xmlns:NS2="urn:EchoIntf"> <NS1:echoMyEmployeeResponse xmlns:NS1="urn:EchoIntf-IEcho"> <return href="#1"/> </NS1:echoMyEmployeeResponse> <NS2:TMyEmployee id="1" xsi:type="NS2:TMyEmployee"> <LastName xsi:type="xsd:string">Swart</LastName> <FirstName xsi:type="xsd:string">Bob</FirstName> <Salary xsi:type="xsd:double">4242</Salary> <Birthdate xsi:type="xsd:dateTime">2006-10-14T20:34:11.6250000+02:00</Birthdate> </NS2:TMyEmployee> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Any idea why I have to modify this SOAP response to make it work? Is it a bug in the .NET importer, or a problem with the Win32 server engine (I have a feeling the latter, since I also need to remove the xsd: prefix in a C# client, just as for a Delphi for .NET client)... I will create a QC entry for it shortly, but first wanted to see if anyone has any further ideas or comments. Groetjes, Bob Swart -- Bob Swart Training & Consultancy (eBob42.com) Forever Loyal to Delphi Blog: www.drbob42.com/blog - RSS: drbob42.com/weblog.xml New Delphi 2006 Courseware e-books at www.eBob42.com/courseware |