Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

I have the same problem with consuming Java WS. On WCF3 config I only add the messageEncoding propery to binding definition and set it to "Mtom". Something like this:

...
<system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="e3" messageEncoding="Mtom">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top