Problem with streaming a DIME attachment with SOAP

Discussion in 'ASP .Net' started by Ipsita, Oct 27, 2004.

  1. Ipsita

    Ipsita Guest

    Hi!

    I am trying SOAP with DIME attachments in web services. For example
    say, I have a file resume.pdf stored somewhere on my server. How does
    the web service send the file to the client, so that the client can
    store it and also read from it. I am trying out with C# and ASP.NET.

    Server Side Web Method:
    -----------------------
    [WebMethod]
    public void GetDoc()
    {
    SoapContext respContext = ResponseSoapContext.Current;
    DimeAttachment dimeAttach = new DimeAttachment("application/msword",
    TypeFormat.MediaType,
    @"C:\Images\Test.doc");
    respContext.Attachments.Add(dimeAttach);
    }

    Client Side:
    ------------
    I intend to populate a text box control with the contents of the file.
    I am using Windows Form in my client.

    private void btnGetDoc_Click(object sender, System.EventArgs e)
    {
    MyDimeService svc = new MyDimeService();
    svc.GetDoc();
    if (svc.ResponseSoapContext.Attachments.Count == 1)
    {
    MessageBox.Show("Got it!\n");
    Stream myStream = svc.ResponseSoapContext.Attachments[0].Stream;

    // move to the buffer
    byte[] buffer = new Byte[myStream.Length];
    myStream.Read(buffer, 0, buffer.Length);
    myStream.Close();
    txtGetDoc.Text = buffer.ToString();
    }
    }

    Note: Is this right? Is this the way I should populate? The code
    compiles, but the output that I get in my textbox is: System.Byte[]

    Please let me know what I am doing wrong.

    Thanks
    Ipsita
     
    Ipsita, Oct 27, 2004
    #1
    1. Advertising

  2. Well, what's happening is that the data sent over the wire is the binary
    content of the PDF. You can't just assign this to some TextBox, who is
    expecting a string. You'll need some component that can display a PDF
    file. (Perhaps you can embed a browser into your form, save the
    downloaded PDF to a temporary file, and then have the embedded browser
    display that file?)


    Ipsita wrote:
    > Hi!
    >
    > I am trying SOAP with DIME attachments in web services. For example
    > say, I have a file resume.pdf stored somewhere on my server. How does
    > the web service send the file to the client, so that the client can
    > store it and also read from it. I am trying out with C# and ASP.NET.
    >
    > Server Side Web Method:
    > -----------------------
    > [WebMethod]
    > public void GetDoc()
    > {
    > SoapContext respContext = ResponseSoapContext.Current;
    > DimeAttachment dimeAttach = new DimeAttachment("application/msword",
    > TypeFormat.MediaType,
    > @"C:\Images\Test.doc");
    > respContext.Attachments.Add(dimeAttach);
    > }
    >
    > Client Side:
    > ------------
    > I intend to populate a text box control with the contents of the file.
    > I am using Windows Form in my client.
    >
    > private void btnGetDoc_Click(object sender, System.EventArgs e)
    > {
    > MyDimeService svc = new MyDimeService();
    > svc.GetDoc();
    > if (svc.ResponseSoapContext.Attachments.Count == 1)
    > {
    > MessageBox.Show("Got it!\n");
    > Stream myStream = svc.ResponseSoapContext.Attachments[0].Stream;
    >
    > // move to the buffer
    > byte[] buffer = new Byte[myStream.Length];
    > myStream.Read(buffer, 0, buffer.Length);
    > myStream.Close();
    > txtGetDoc.Text = buffer.ToString();
    > }
    > }
    >
    > Note: Is this right? Is this the way I should populate? The code
    > compiles, but the output that I get in my textbox is: System.Byte[]
    >
    > Please let me know what I am doing wrong.
    >
    > Thanks
    > Ipsita



    --

    Scott Mitchell

    http://www.4GuysFromRolla.com

    * When you think ASP.NET, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Oct 27, 2004
    #2
    1. Advertising

  3. Ipsita

    Ipsita Guest

    Hi Scott,

    If data that is sent over the wire is binary, can I read it as a
    BinaryReader
    eg.
    BinaryReader r = new
    BinaryReader(svc.ResponseSoapContext.Attachments[0].Stream);

    Then what do I have to do exactly to populate it to a textbox control?
    I am a beginner, so wanted to keep things simple :)
    If I do a txtGetDoc.Text = r.ReadString();.....I get a runtime error.

    Can you point out how I could fix this problem with a code snippet? I
    will be very grateful.

    Thanks
    Ipsita



    "Scott Mitchell [MVP]" <> wrote in message news:<m4Tfd.35590$>...
    > Well, what's happening is that the data sent over the wire is the binary
    > content of the PDF. You can't just assign this to some TextBox, who is
    > expecting a string. You'll need some component that can display a PDF
    > file. (Perhaps you can embed a browser into your form, save the
    > downloaded PDF to a temporary file, and then have the embedded browser
    > display that file?)
    >
    >
    > Ipsita wrote:
    > > Hi!
    > >
    > > I am trying SOAP with DIME attachments in web services. For example
    > > say, I have a file resume.pdf stored somewhere on my server. How does
    > > the web service send the file to the client, so that the client can
    > > store it and also read from it. I am trying out with C# and ASP.NET.
    > >
    > > Server Side Web Method:
    > > -----------------------
    > > [WebMethod]
    > > public void GetDoc()
    > > {
    > > SoapContext respContext = ResponseSoapContext.Current;
    > > DimeAttachment dimeAttach = new DimeAttachment("application/msword",
    > > TypeFormat.MediaType,
    > > @"C:\Images\Test.doc");
    > > respContext.Attachments.Add(dimeAttach);
    > > }
    > >
    > > Client Side:
    > > ------------
    > > I intend to populate a text box control with the contents of the file.
    > > I am using Windows Form in my client.
    > >
    > > private void btnGetDoc_Click(object sender, System.EventArgs e)
    > > {
    > > MyDimeService svc = new MyDimeService();
    > > svc.GetDoc();
    > > if (svc.ResponseSoapContext.Attachments.Count == 1)
    > > {
    > > MessageBox.Show("Got it!\n");
    > > Stream myStream = svc.ResponseSoapContext.Attachments[0].Stream;
    > >
    > > // move to the buffer
    > > byte[] buffer = new Byte[myStream.Length];
    > > myStream.Read(buffer, 0, buffer.Length);
    > > myStream.Close();
    > > txtGetDoc.Text = buffer.ToString();
    > > }
    > > }
    > >
    > > Note: Is this right? Is this the way I should populate? The code
    > > compiles, but the output that I get in my textbox is: System.Byte[]
    > >
    > > Please let me know what I am doing wrong.
    > >
    > > Thanks
    > > Ipsita
     
    Ipsita, Oct 28, 2004
    #3
  4. Ipsita wrote:
    > If data that is sent over the wire is binary, can I read it as a
    > BinaryReader
    > eg.
    > BinaryReader r = new
    > BinaryReader(svc.ResponseSoapContext.Attachments[0].Stream);


    See, the problem is not that it's just binary, but that it's stored in
    some format. A PDF document is not just a string, it's a set of bytes
    that a PDF reader, like Acrobat, can disassemble to construct the
    nice-looking PDF document you see. Ditto for a Word document, or an
    Excel spreadsheet, or an MP3 player.

    The point is, you can't just grab the content of the PDF and hope to
    squirt it to a TextBox. You have to have some sort of control that
    knows all about the PDF specification and, given the PDF contents, can
    display it. (Same for a Word doc, same for an Excel spreadsheet, etc.)

    My suggestion was that you might be able to use the browser (IE) to
    handle the display. This would involve saving the PDF file to disk,
    then directing the browser to the PDF file. Just a thought...

    Might I make a suggestion? Before you get too wrapped up trying to pass
    such a complex document object across the wire with DIME/WS-Attachments,
    why not first just work on passing a string back and displaying it in a
    TextBox, just as a "proof of concept?"

    hth



    > Then what do I have to do exactly to populate it to a textbox control?
    > I am a beginner, so wanted to keep things simple :)
    > If I do a txtGetDoc.Text = r.ReadString();.....I get a runtime error.
    >
    > Can you point out how I could fix this problem with a code snippet? I
    > will be very grateful.
    >
    > Thanks
    > Ipsita
    >
    >
    >
    > "Scott Mitchell [MVP]" <> wrote in message news:<m4Tfd.35590$>...
    >
    >>Well, what's happening is that the data sent over the wire is the binary
    >>content of the PDF. You can't just assign this to some TextBox, who is
    >>expecting a string. You'll need some component that can display a PDF
    >>file. (Perhaps you can embed a browser into your form, save the
    >>downloaded PDF to a temporary file, and then have the embedded browser
    >>display that file?)
    >>
    >>
    >>Ipsita wrote:
    >>
    >>>Hi!
    >>>
    >>>I am trying SOAP with DIME attachments in web services. For example
    >>>say, I have a file resume.pdf stored somewhere on my server. How does
    >>>the web service send the file to the client, so that the client can
    >>>store it and also read from it. I am trying out with C# and ASP.NET.
    >>>
    >>>Server Side Web Method:
    >>>-----------------------
    >>>[WebMethod]
    >>>public void GetDoc()
    >>>{
    >>> SoapContext respContext = ResponseSoapContext.Current;
    >>> DimeAttachment dimeAttach = new DimeAttachment("application/msword",
    >>> TypeFormat.MediaType,
    >>> @"C:\Images\Test.doc");
    >>> respContext.Attachments.Add(dimeAttach);
    >>>}
    >>>
    >>>Client Side:
    >>>------------
    >>>I intend to populate a text box control with the contents of the file.
    >>>I am using Windows Form in my client.
    >>>
    >>>private void btnGetDoc_Click(object sender, System.EventArgs e)
    >>>{
    >>> MyDimeService svc = new MyDimeService();
    >>> svc.GetDoc();
    >>> if (svc.ResponseSoapContext.Attachments.Count == 1)
    >>> {
    >>> MessageBox.Show("Got it!\n");
    >>> Stream myStream = svc.ResponseSoapContext.Attachments[0].Stream;
    >>>
    >>> // move to the buffer
    >>> byte[] buffer = new Byte[myStream.Length];
    >>> myStream.Read(buffer, 0, buffer.Length);
    >>> myStream.Close();
    >>> txtGetDoc.Text = buffer.ToString();
    >>> }
    >>>}
    >>>
    >>>Note: Is this right? Is this the way I should populate? The code
    >>>compiles, but the output that I get in my textbox is: System.Byte[]
    >>>
    >>>Please let me know what I am doing wrong.
    >>>
    >>>Thanks
    >>>Ipsita



    --

    Scott Mitchell

    http://www.4GuysFromRolla.com

    * When you think ASP.NET, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Oct 29, 2004
    #4
    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. Ipsita
    Replies:
    1
    Views:
    3,289
    bruce barker
    Oct 29, 2004
  2. David Dundua

    Referenced DIME attachment

    David Dundua, Jul 23, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    126
    David Dundua
    Jul 23, 2003
  3. Oleg

    SoapExtensions, DIME Attachment and Pipes

    Oleg, Sep 30, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    191
  4. Ipsita

    How to send a DIME attachment with SOAP

    Ipsita, Oct 29, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    388
    Dan Rogers
    Nov 16, 2004
  5. David Talbot

    WSE 2.0 DIME Streaming Problem

    David Talbot, Aug 2, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    143
    Georgi Vajarov
    Aug 3, 2005
Loading...

Share This Page