Question:
I have to send a POST request to a webservice with an XML Soap and a zip file attachment.
The result should be
POST /InvioTelematicoSS730pMtomWeb/InvioTelematicoSS730pMtomPort HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/related; type="text/xml"; start="<rootpart@soapui.org>";boundary="----=_Part_3_640244516.1446475016664"
SOAPAction: ""
Authorization: Basic VVpWUzZCV1M6UFhOREVLNlA=
MIME-Version: 1.0
Content-Length: 8036
Host: invioSS730pTest.sanita.finanze.it
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
------=_Part_3_640244516.1446475016664"
Content-Type: text/xml; charset=UTF-8"
Content-Transfer-Encoding: 8bit"
Content-ID: <rootpart@soapui.org>"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ejb="http://ejb.invioTelematicoSS730p.sanita.finanze.it/">
<soapenv:Header/>
<soapenv:Body>
<ejb:inviaFileMtom>
<nomeFileAllegato>20141201-20141210_20151027182804.ZIP</nomeFileAllegato>
<pincodeInvianteCifrato>XXXXXXXXXXXXXXX</pincodeInvianteCifrato>
<datiProprietario>
<codiceRegione>000</codiceRegione>
<codiceAsl>000</codiceAsl>
<codiceSSA>88888888</codiceSSA>
<cfProprietario>PROVAX00X00X000Y</cfProprietario>
</datiProprietario>
<documento/>
</ejb:inviaFileMtom>
</soapenv:Body>
</soapenv:Envelope>"
------=_Part_3_640244516.1446475016664"
Content-Type: application/octet-stream"
Content-Transfer-Encoding: binary"
Content-ID: <20141201-20141210_20151027182804.ZIP>"
Content-Disposition: attachment; name="20141201-20141210_20151027182804.ZIP""
[file_content]
------=_Part_3_640244516.1446475016664--"
I've tried by creating an HttpRequest and after sets the header fields, i've used the LoadBodyFromString to load the XML object and the FILETOSTR of the zip, but it doesn't use the boundary so the result is not accepted. So i've tried by creating a MIME object, adding the xml and the file as parts (AppendParts); this return a MIME object with its own header and boundary, but i don't know how to load it in the HttpRequest object. Can someone help me?
Solved! Even if i still have problems with the attachment's data, so i'm going to open another question about it.
Btw, for those who want to know how i've handle it, here you are:
. first i've created the soap object with the XML object ;
. then i've created a MIME object and added the soap object and the attachment file with the AppendPart() method and saving the boundary value;
. so i've created the HttpRequest object, where i've set the Header fields ( Host, SoapAction, Boundary etc ) and composed the body by passing the MIME body only ( using the GetEntireBody() method ) as parameter for the LoadBodyFromString() of the HttpRequest object;
. lastly, i've invocked the SynchronousRequest() method of the Http object
It is certainly not the best way to do it, but it works for me so i hope it could be usefull for someone.
If you have MIME, you could try to get XML string by using method GetXml() of MIME object and then pass this XML string into the method PostXml() of Http object.
Thanks for the answer,
it could be a solution but:
- webservice require several fields in header like authorization, host etc... does the PostXml() handle them?
- how to upload an attachment ( second MIME in example ) with PostXml / Http object?
Thanks
To answer your second question - if I understood correctly, you've already created MIME object containing zip file. The method GetXml() returns entire XML, including zip – so, you don't have to worry about attachment.
To answer your first question – if header has additional options, when the PostXml() is not suitable, because it supports only web address as an endpoint. Instead, you have to create synchronous HttpRequest, set its parameters and call the method request.LoadBodyFromString(xmlStr,"utf-8"), where xmlStr is your string, retrieved earlier by GetXml(). After that, you can get response = http.SynchronousRequest(..., request) There is example, available at: http://www.example-code.com/csharp/http_xmlHttpRequestVerbs.asp
Yes its true, i've created a MIME object with 2 "sub-parts", MIME themselves: the Soap XML part and the binary file data part, so this object has his own Head ( Content-Type: multipart/mixed; boundary=... ) and two boundary parts.
But if i use LoadBodyFromString method in the HttpRequest object, this add the whole MIME object as body, and the webserver refuse it.
Same problem with the Http.PostXML( MIME.GetXML() ): the GetXML return an object that the webserver doesn't accept.
Instead, i tried to use the Http object by setting the header fields and using the PostXML method with the pure xml object, with the binary data of the zip encoded in base64 inside the xml tag: the server accepted it!
So the problem is the MTOM technology, but i need to find the way to attach the binary data of the file to the Http object with MTOM correctly because now is advice by the webserver, but sooner will be required.
Many thanks for sharing your work. I am in the same situation: I need MTOM.
Hi b_mat_ita, I have the same problem (730), have you found a solution ? If I understood: - now you are able to send base64 zip file that follow the soap - but using b64 encoding and not the mtom...
it is correct ? Ciao daniele
Hi Daniele,
yes i've solved it, you can find the solution at the top of this discussion; i used the mtom technology with binary encoding, writing the zip file with b64 enconding within the soap it could work for a while but they have declared that soon will be accepted only the mtom technology.
Hope to be helpful. Ciao
I created an example here, but it requires Chilkat v9.5.0.55 which is due out in a week..
Android: SOAP with MTOM XOP Attachment
C: SOAP with MTOM XOP Attachment
C#: SOAP with MTOM XOP Attachment
C# WinRT: SOAP with MTOM XOP Attachment
C++: SOAP with MTOM XOP Attachment
Classic ASP: SOAP with MTOM XOP Attachment
DataFlex: SOAP with MTOM XOP Attachment
Delphi ActiveX: SOAP with MTOM XOP Attachment
Delphi DLL: SOAP with MTOM XOP Attachment
Java: SOAP with MTOM XOP Attachment
Lianja: SOAP with MTOM XOP Attachment
MFC: SOAP with MTOM XOP Attachment
Node.js: SOAP with MTOM XOP Attachment
Objective-C: SOAP with MTOM XOP Attachment
Perl: SOAP with MTOM XOP Attachment
PHP ActiveX: SOAP with MTOM XOP Attachment
PHP Extension: SOAP with MTOM XOP Attachment
PowerBuilder: SOAP with MTOM XOP Attachment
PowerShell: SOAP with MTOM XOP Attachment
PureBasic: SOAP with MTOM XOP Attachment
Python: SOAP with MTOM XOP Attachment
Ruby: SOAP with MTOM XOP Attachment
SQL Server: SOAP with MTOM XOP Attachment
Swift: SOAP with MTOM XOP Attachment
Tcl: SOAP with MTOM XOP Attachment
Unicode C: SOAP with MTOM XOP Attachment
Unicode C++: SOAP with MTOM XOP Attachment
VB.NET: SOAP with MTOM XOP Attachment
VB.NET WinRT: SOAP with MTOM XOP Attachment
VBScript: SOAP with MTOM XOP Attachment
Hi everybody, Thank you "Chilkat" ! I will buy the new release asap it will be ready to buy.
When my testing script will works fine I will publish it here in this forum topic. So everybody need to send data to Italy MEF for 730 healtcare invoice collection... will have a trace...
Merry Christmas and Happy New Year daniele