"Cannot access a closed Stream" when using DimeAttachment

Discussion in 'ASP .Net Web Services' started by Michael, May 13, 2004.

  1. Michael

    Michael Guest

    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
     
    Michael, May 13, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William F. Robertson, Jr.
    Replies:
    1
    Views:
    999
    Kathy Burke
    Jun 25, 2003
  2. pete
    Replies:
    1
    Views:
    3,012
    Jon Yates
    Aug 29, 2003
  3. timmso
    Replies:
    1
    Views:
    574
    Alex Papadimoulis
    Dec 12, 2003
  4. Replies:
    2
    Views:
    581
  5. KodeCruncher
    Replies:
    2
    Views:
    255
    John Fullmer
    May 16, 2006
Loading...

Share This Page