I am working with a java-written web service called JasperServer. I would like to obtain a file from the web service and save it on my local.
The web service provides a get() method; it requests a String of XML, and returns a String, and the target file as a MIME attachment:
public string get(string requestXmlString)
Right now I try to use a string to take in the response:
String res2 = webServiceClient.get(xmlInput);
It gives me an Exception:
Client found response content type of 'multipart/related; type="text/xml"; start="<7817FB68F69B037F5A5DEDE2AC105A65>"; boundary="----=_Part_2_1089980294.1393857885100"', but expected 'text/xml'.
The request failed with the error message:
------=_Part_2_1089980294.1393857885100
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <7817FB68F69B037F5A5DEDE2AC105A65>
So my question is how to consume an String response with MIME attachment in C# .Net. And how to save it to my local?
You need a component for parsing MIME format described by RFC 822/2045 and extensions. .NET framework doesn't include built-in classes for that.
I've good experience with Mime4Net component (it is based on port from Apache mime4j):
Stream mimeMsgStream;
var m = new MimeMessage(mimeMsgStream);
MimeMessage provides DOM for MIME structure and attachment content could be easily extracted. Also note that Mime4Net is free only for non-commercial usage.