I have the need to create a c# application that consumes a Java 1.4 web service. This web service has no WSDL, and no I cannot make them create one, and I must use this service.
The content type of the return is Content-Type: multipart/form-data with an arbitrary boundary. The content from fiddler looks like this:
HTTP/1.0 200 OK
Content-Type: multipart/form-data; boundary=---------------------------MultiPartFormControl7d2fb2f20039a
Servlet-Engine: Tomcat Web Server/3.2.3 (JSP 1.1; Servlet 2.2; Java 1.4.2_11; Linux 2.6.18-371.8.1.el5 i386; java.vendor=Sun Microsystems Inc.)
-----------------------------MultiPartFormControl7d2fb2f20039a
Content-Disposition: form-data; name="806307234.xml" filename="806307234.xml"
Content-Type: application/octet-stream
<*XML contents go here*>
-----------------------------MultiPartFormControl7d2fb2f20039a
Content-Disposition: form-data; name="806307873.jpg" filename="806307873.jpg"
Content-Type: image/jpeg
<*binary data goes here*>
-----------------------------MultiPartFormControl7d2fb2f20039a
Content-Disposition: form-data; name="806307876.jpg" filename="806307876.jpg"
Content-Type: image/jpeg
<*binary data goes her**>
-----------------------------MultiPartFormControl7d2fb2f20039a
When attempting to use .ReadAsMultipartAsync() I encounter the following error when attempting to return the result into the MultipartMemoryStreamProvider:
<Error parsing MIME multipart body part header byte 143 of data segment System.Byte[]>
Here is my code snippet:
Uri webServiceUri = new Uri(@"http://endpoint");
string document = @"Contains XML for SOAP call";
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, webServiceUri);
HttpContent stringContent = new StringContent(document, Encoding.UTF8, "text/xml");
requestMessage.Content = stringContent;
HttpClient client = new HttpClient();
Task<HttpResponseMessage> httpRequest = client.SendAsync(requestMessage,
HttpCompletionOption.ResponseHeadersRead, CancellationToken.None);
HttpResponseMessage httpResponse = httpRequest.Result;
HttpContent returnContent = httpResponse.Content;
Task<MultipartMemoryStreamProvider> multiPartTask = returnContent.ReadAsMultipartAsync();
MultipartMemoryStreamProvider mpmsProvider = multiPartTask.Result; <*** ERROR OCCURS HERE ***>
Stream multipartStream = mpmsProvider.GetStream(returnContent, returnContent.Headers);