"Cannot access a closed Stream" when using DimeAttachment

M

Michael

Hi all..

I'm trying to work with DimeAttachment.
Please, take a look at code here - it's very simple to understand.

Server Side:
public class MyDimeService : System.Web.Services.WebService
{
[WebMethod]
public void DoNothing() { }
}

Client Side:
public class ClientClass
{
private void CallServer()
{
MyDimeService svc = new MyDimeService();
DimeAttachment dimeAttach = new DimeAttachment("image/gif",
TypeFormatEnum.MediaType, new MemoryStream());

dimeAttach.Stream = new MemoryStream();
dimeAttach.Stream.Write(new Byte[10], 0, 10);

svc.RequestSoapContext.Attachments.Add(dimeAttach);
svc.DoNothing();

dimeAttach.Stream.Write(new Byte[10], 0, 10);
}
}

What I get, when executing the last command in CallServer() function
is:
An unhandled exception of type 'System.ObjectDisposedException'
occurred in mscorlib.dll
Additional information: Cannot access a closed Stream.

Why do we want to do it this way ?
This is a simplified code, just to show the problem, but in general
what we want is -> pass a big file in chunks from one side to another
(from client to server).

We can, ofcource, for every chunk, create a new stream and write data
of next chunk to it, but in this case we get much much memory usage.
We have to activate garbage collector to free memory, but, this is not
the best way to do things.

There are 2 questions:
1 --> any idea, why do I get this exception ?
2 --> any idea how to solve the general problem ?

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top