Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: How to use ObjectToSoap and SoapToObject?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Apr 23, 2018 10:17 PM Last Post By: Adam Hair
Adam Hair

Posts: 18
Registered: 7/26/17
How to use ObjectToSoap and SoapToObject?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 15, 2018 9:05 PM
Hi,

I'm connecting to a SOAP server and I'm retrieving a lot of information. I'm wanting to utilise the ObjectToSoap and SoapToObject methods, so that I can store what I've received into a file, and then read it back from a file and work through the data at a later date without having to connect to the service and download the information again.

I'm having problems where the file being created is blank or empty, yet the data coming through from the server is significant. (I can view the data and save it to an XML file by using the AfterExecute Event and accessing the data stream).

I've struggled to find the references to help me, and the following is what I've obtained from reading other newsgroup posts I've googled, but it doesn't appear to be working for me:

_Resp := (RIO1 as ReferenceDataService.GenericCodeSet).GenericCodeSet(Param1, Param2, Param3);
XMLDoc1.Active := False;
XMLDoc1.XML.Clear;
XMLDoc1.Active := true;
ARootNode := XMLDoc1.CreateNode('MyRemotable');
NewNode := _Resp.ObjectToSOAP(ARootNode, ARootNode, Rio1.Converter, '', '', '', [], RefID);
XMLDoc1.SaveToFile('c:\temp\MyResponse.xml');


My plan then was to use SOAPToObject to load back into a new instance of _Resp which I thought would just be the reverse process.

Am I trying to achieve this the wrong way? Or can anyone see why the above would result in a blank file?

I'm not sure if it's relevant, but the data returning from the server looks like:

<S:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
	<env:Header/>
	<S:Body>
		<ns1:GenericCodeSetResponse xmlns:ns1="http://agriculture.gov.au/nexdoc/GenericCodeSetSoap_1.0">
			<ns1:genericCodeSetResponse>
				<ns1:codeSetName>ECM_AHECC_CODE</ns1:codeSetName>
				<ns1:listCodeSet>
					<ns1:listPosition>1</ns1:listPosition>
					<ns1:listItemCodeSet>
						<ns1:key>CODE</ns1:key>
						<ns1:value>02011010</ns1:value>
						<ns1:type>string</ns1:type>
					</ns1:listItemCodeSet>
					<ns1:listItemCodeSet>
						<ns1:key>DESCRIPTION</ns1:key>
						<ns1:value>BOVINE CARCASSES AND HALF-CARCASSES, FRESH OR CHILLED - BEEF</ns1:value>
						<ns1:type>string</ns1:type>
					</ns1:listItemCodeSet>
					<ns1:listItemCodeSet>
						<ns1:key>START_DATE</ns1:key>
						<ns1:value>1990-01-01T00:00:00.0</ns1:value>
						<ns1:type>dateTime</ns1:type>
					</ns1:listItemCodeSet>
					<ns1:listItemCodeSet>
						<ns1:key>END_DATE</ns1:key>
						<ns1:value>null</ns1:value>
						<ns1:type>dateTime</ns1:type>
					</ns1:listItemCodeSet>
					<ns1:listItemCodeSet>
						<ns1:key>UPDATED_DATE</ns1:key>
						<ns1:value>2017-12-08T18:31:50.828</ns1:value>
						<ns1:type>dateTime</ns1:type>
					</ns1:listItemCodeSet>
				</ns1:listCodeSet>
				<ns1:listCodeSet>
					<ns1:listPosition>2</ns1:listPosition>
					<ns1:listItemCodeSet>
						<ns1:key>CODE</ns1:key>
						<ns1:value>02011040</ns1:value>
						<ns1:type>string</ns1:type>
					</ns1:listItemCodeSet>
					<ns1:listItemCodeSet>
						<ns1:key>DESCRIPTION</ns1:key>
						<ns1:value>MEAT OF BOVINE ANIMALS, FRESH OR CHILLED BOVINE CARCASSES AND HALF-CARCASSES, FRESH OR CHILLED</ns1:value>
						<ns1:type>string</ns1:type>
					</ns1:listItemCodeSet>
					<ns1:listItemCodeSet>
						<ns1:key>START_DATE</ns1:key>
						<ns1:value>2012-01-01T00:00:00.0</ns1:value>
						<ns1:type>dateTime</ns1:type>
					</ns1:listItemCodeSet>
					<ns1:listItemCodeSet>
						<ns1:key>END_DATE</ns1:key>
						<ns1:value>null</ns1:value>
						<ns1:type>dateTime</ns1:type>
					</ns1:listItemCodeSet>
					<ns1:listItemCodeSet>
						<ns1:key>UPDATED_DATE</ns1:key>
						<ns1:value>2017-12-08T18:31:50.833</ns1:value>
						<ns1:type>dateTime</ns1:type>
					</ns1:listItemCodeSet>
				</ns1:listCodeSet>
...


Thanks & Regards

Adam.
Adam Hair

Posts: 18
Registered: 7/26/17
Re: How to use ObjectToSoap and SoapToObject?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 23, 2018 10:17 PM   in response to: Adam Hair in response to: Adam Hair
Another developer has assisted me with this to finally find a solution. Hopefully the below helps someone else down the track...

ObjectToSOAP (After receiving the response to save to a file)....

_SoapResponse := (RIO1 as MyService.MyPort).GenericCodeSet('CODE','', '');
XMLDoc1.Active := False;
XMLDoc1.XML.Clear;
XMLDoc1.Active := true;

ARootNode := XMLDoc1.CreateNode('MyRemotable');
NewNode := _GenericCodeSetResp.ObjectToSOAP(ARootNode, ARootNode, Rio1.Converter, 'MyNodeName', 'MyNodeNameSpace', 'MyChildNameSpace', [], RefID);
XMLDoc1.SaveToFile('c:\temp\MyResponse.xml');
XMLDoc1.Active := False;


SOAPToObject (To load back in again)....
var
RefID : String;
begin
XMLDoc1.LoadFromFile('c:\temp\MyResponse.xml');
_SoapResponse := ListCodeSet.Create;
_SoapResponse.ObjectToSOAP(XMLDoc1.Node, XMLDoc1.Node, RIO1.Converter, '','','',[], Refid);
end;

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02