0

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);
John Saunders
  • 157,405
  • 24
  • 229
  • 388
stieferj
  • 1
  • 1
  • Based on the file names, having the exact same byte number failing and some other hits in your code, I'm pretty sure you and I are working against the same service :) I'm having the same issue among a myriad of others :/ –  Nov 16 '15 at 16:46

2 Answers2

0

You should first point your browser at the service to see if you can view the wsdl on browser first.

http://YourLinuxBox:8080/SomeService.wsdl

Also what application server this service hosted under? Tomcat? JBoss? For example if tomcat, fail "catalina.out" under logs folder and see if the service is loaded properly.

Here's a piece which shows, in particular for dotnet developers who're not familiar with linux, how to setup Java-ws on Tomcat/Linux, and consume the Java-ws from C#:

https://gridwizard.wordpress.com/2014/12/26/java-ws-and-dotnet-interop-example/ https://gridwizard.wordpress.com/2014/12/28/install-tomcat-on-fedora-vm-for-msdev/

Jaye
  • 142
  • 4
0

You are using two images with extension ".jpg" and you are using Content-Type of image/jpeg. Based on this SO answer the MIME types image/jpg and image/jpeg are not the same. So you might want to try changing the Content-Type of your images to image/jpg like so:

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/jpg

<*binary data goes here*>    
-----------------------------MultiPartFormControl7d2fb2f20039a
Content-Disposition: form-data; name="806307876.jpg" filename="806307876.jpg"
Content-Type: image/jpg

<*binary data goes her**>    
-----------------------------MultiPartFormControl7d2fb2f20039a
Community
  • 1
  • 1
Amadeus Sánchez
  • 1,887
  • 1
  • 20
  • 29