0

I have been successful in using zeep when calling (remote) methods and downloading attachments.

I have now come across a method that requires me to upload a file. The file needs to be passed as an attachment. I normally call a remote web service method as follows:

client.service.fooMethod(arg1,arg2,...)

In my particular case, arg1 is a URI, a file I wish to upload to the server. It needs to be uploaded as an attachment. How would I go about doing this?

Here is a more concrete example:

The Method name is UploadPortfolios and has the following schema:

<xs:element name="UploadPortfolio">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="tns:URI"/>
      <xs:element ref="tns:PortfolioID"/>
      <xs:element ref="tns:AsOfDate"/>
      <xs:element minOccurs="0" ref="tns:SuppressPositionLog"/>
      <xs:element minOccurs="0" ref="tns:PositionDetailLogAsAttachment"/>
      <xs:element minOccurs="0" ref="tns:UploadSharedPortfolio"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

I use zeep in python to to call the UploadPortfolios. The uri argument needs to include the string cid:<someContentID> where <someContentID> is the Content ID of the attachment:

portfolio_management_wsdl = 'https://ondemand.uat.riskmetrics.com/ondemand/soap/PortfolioManagement?wsdl'
client_pfm = Client(portfolio_management_wsdl, transport=transport, wsse=wsse)
uri = r'cid://SomeDataFile.xml'
args = {'URI':uri, 'AsOfDate':'20160129'}
result = client_pfm.service.UploadPortfolios(**args)

needless the say the above wont work, because, somehow I need to send in the attachment.

Using SoapUI (https://www.soapui.org/downloads/soapui.html) I can call the function without an issue. The following is the raw data generated by SoapUI and sent to the server (some parts have been omitted)

POST https://ondemand.uat.riskmetrics.com/ondemand/soap/PortfolioManagement.PortfolioManagementHttp    sSoap12Endpoint/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="application/soap+xml"; action="urn:RiskMetricsWS:1.0:PortfolioManagement:UploadPortfolio"; boundary="----=_Part_46_453204030.1495210657807"
MIME-Version: 1.0
Content-Length: 7668
Host: ondemand.uat.riskmetrics.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)


------=_Part_46_453204030.1495210657807
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"; action="UploadPortfolio"
Content-Transfer-Encoding: 8bit
Content-ID: <rootpart@soapui.org>

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsdl="http://..." xmlns:xsd="http://..." xmlns:xsd1="http://...">
   <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" ... </soap:Header>
   <soap:Body>
      <wsdl:UploadPortfolio>
         <wsdl:URI><inc:Include href="cid:530345234005" xmlns:inc="http://www.w3.org/2004/08/xop/include"/></wsdl:URI>
         <wsdl:PortfolioID>TestPtf_RML4</wsdl:PortfolioID>
         <wsdl:AsOfDate>20170509</wsdl:AsOfDate>
         <wsdl:SuppressPositionLog>false</wsdl:SuppressPositionLog>
         <wsdl:PositionDetailLogAsAttachment>true</wsdl:PositionDetailLogAsAttachment>
         <wsdl:UploadSharedPortfolio>true</wsdl:UploadSharedPortfolio>
      </wsdl:UploadPortfolio>
   </soap:Body>
</soap:Envelope>
------=_Part_46_453204030.1495210657807
Content-Type: text/xml; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-ID: <530345234005>
Content-Disposition: attachment; name="SomeDataFile.xml"

<someInformation>
...
</someInformation>

------=_Part_46_453204030.1495210657807--
Mohrez
  • 11
  • 3

1 Answers1

0

I tried using transport_with_attach created by ellethee and passed client.attach(filename) as the argument for URI. It looks promising and the message has the correct form. However the server responds with:

 javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
 Message: Premature end of file.

which has something to do with malformed xml (I think)

Mohrez
  • 9
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment](http://stackoverflow.com/help/privileges/comment) on any post. Also check this [what can I do instead](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). – thewaywewere May 23 '17 at 01:26