Title: SOAP service with DIME Attachment using PocketSOAP
Question: How to use PocketSOAP to connect to a SOAP service with Attachment using DIME encoding?
Answer:
First you have to download and install PocketSOAP, then you have to create a new project and put PocketSOAP_TLB and PocketSOAPAttachments_TLB on the uses clause.
To import and create these Type Libraries (TLBs), go the menu "Project" - "Import Type Library..." and on the dialog mark the checkbox "Generate Component Wrapper". Select "Pocket SOAP 1.x.x Type Library" and click on "Create Unit". Repeat the process selecting "PocketSOAP Attachmments 1.x.x Type Library".
The following example connects to a SOAP service to get echo an attachmed file using DIME.
Declare the following variables:
var
mgr: IAttachmentManger;
atts: ISoapAttachments;
att: ISoapAttachment;
env: ISOAPEnvelope;
http: IHTTPTransportAdv;
st: ISOAPTransport;
params, nodes: ISOAPNodes;
nr, n: ISOAPNode;
Value: OLEVariant;
Location: AttachmentLocation;
serialize, uri, href: WideString;
To create the SOAP service wrapper use the following code:
begin
env := CoCoEnvelope.Create;
env.Set_EncodingStyle('');
env.SetMethod('echoAttachments', 'http://xsd.prototypes.4s4c.com/dime/');
To create the SOAP attachment manager use the following code:
mgr := CoCoAttachmentManager.Create;
mgr.Set_Format(formatDime);
env.Get_URI(uri);
env.Get_Parameters(params);
params.Create('attachments', Unassigned, uri, '', '', nr);
env.Get_URI(uri);
nr.Get_Nodes(nodes);
nodes.Create('attachment', Unassigned, uri, '', '', n);
mgr.Get_Request(atts);
atts.Create('c:\image.gif', tnfMediaType, 'application/octectstream', att);
att.Get_Uri(uri);
n.Set_href(uri);
To create the HTTP transport handler use the following code:
http := CoHTTPTransport.Create;
http.Set_SOAPAction('test');
mgr._Set_Transport(http);
st := mgr as ISOAPTransport;
env.Serialize(serialize);
st.Send('http://soap.4s4c.com/dime2/sf.soap', serialize);
To get the result use the following code:
env.Parse(st, '');
env.Get_Parameters(params);
env.Get_URI(uri);
params.Get_ItemByName('attachment', uri, n);
n.Get_href(href);
mgr.Get_Response(atts);
atts.Find(href, att);
att.Get_Located(Location);
if Location = attInMemory then
att.Save('c:\att.gif');
att.Get_body(Value);
ShowMessage(Value);
end;