How to use Stream instead of byte[] in C# client with a Java MTOM webservice

女生的网名这么多〃 提交于 2019-12-08 06:27:51

问题


I have a java webservice generated with CXF, and with MTOM enabled.

On the java side, I'm using DataHandler instead of byte[] to send a large file.

If I generate a Java client, it is working fine, declaring DataHandler on the client as well.

The problem is when I try to create a C#.net client.

Using Visual Studio 2010 to generate the client code, it declares the field as byte[] and not as a Stream. This is a problem, because on the client side it is reading and allocation all data to fill the byte[].

Seeing some examples of MTOM and C#, they use Strem instead of byte[].

How can I generate the client code to use Stream instead of byte[] in C#?

Here is the wsdl section using the mtom:

<xs:complexType name="wsDtoCampoRespostaFotografia">
<xs:complexContent>
<xs:extension base="tns:wsDtoCampoResposta">
<xs:sequence>
<xs:element xmlns:ns4="http://www.w3.org/2005/05/xmlmime" minOccurs="0"   name="valorRespostaFotografia" ns4:expectedContentTypes="application/octet-stream" type="xs:base64Binary"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Edit: The problem I'm having is memory allocation. When reading a lot of records with, or a record with a large file, the client throws an exception (due to memory allocation).

Calling the webservice using byte[], the client loads all data in memory, even before giving the result to the rest of the code to handle it. When using Stream I can have access to the result of the webservice, and I can write the content of the Stream to a file, without loading into memory, avoiding out of memory problems.

来源:https://stackoverflow.com/questions/15421851/how-to-use-stream-instead-of-byte-in-c-sharp-client-with-a-java-mtom-webservic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!