How to send a DIME attachment with SOAP

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

  1. Ipsita

    Ipsita Guest

    Hi!

    I am trying SOAP with DIME attachments in web services. The web
    service sends the file as attachment say "test.doc", and the client
    has to read that and populate it in a textbox control. I had asked
    this question earlier, and got the reply that the data is tranferred
    in binary format on the wire. I read the stream, and convert it to
    string, but I get some junk characters in my textbox. I am writing my
    code below, so that you can see what I am doing wrong, and correct me.
    This is what I do:

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

    On 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");
    // Get the stream and do something with it
    Stream s = svc.ResponseSoapContext.Attachments[0].Stream;
    byte [] binaryData = new byte[s.Length];
    long bytesRead = s.Read(binaryData, 0, binaryData.Length);
    s.Close();
    string base64String;
    try
    {
    base64String = System.Convert.ToBase64String(binaryData, 0,

    binaryData.Length);
    }
    catch (System.ArgumentNullException)
    {
    System.Console.WriteLine("Binary data array is null.");
    return;
    }
    txtGetDoc.Text = base64String;
    } //end of if
    } //end of private..

    Waiting for an answer...

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

  2. Ipsita

    bruce barker Guest

    what are you expecting to appear in the textbox?

    from your code I'd expect the textbox to contain the base64 string which is
    the encoding of the binary data, and from your description it sounds like
    you are getting that.

    a textbox only supports displaying plain text, if test.doc cannot be viewed
    correctly with notepad.exe, a textbox cannot either.

    -- bruce (sqlwork.com)



    "Ipsita" <> wrote in message
    news:...
    > Hi!
    >
    > I am trying SOAP with DIME attachments in web services. The web
    > service sends the file as attachment say "test.doc", and the client
    > has to read that and populate it in a textbox control. I had asked
    > this question earlier, and got the reply that the data is tranferred
    > in binary format on the wire. I read the stream, and convert it to
    > string, but I get some junk characters in my textbox. I am writing my
    > code below, so that you can see what I am doing wrong, and correct me.
    > This is what I do:
    >
    > On Server:
    > ----------
    > [WebMethod]
    > public void GetDoc()
    > {
    > SoapContext respContext = ResponseSoapContext.Current;
    > DimeAttachment dimeAttach = new DimeAttachment("application/msword",
    > TypeFormat.MediaType,
    > @"D:\Images\Test.doc");
    > respContext.Attachments.Add(dimeAttach);
    > }
    >
    > On 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");
    > // Get the stream and do something with it
    > Stream s = svc.ResponseSoapContext.Attachments[0].Stream;
    > byte [] binaryData = new byte[s.Length];
    > long bytesRead = s.Read(binaryData, 0, binaryData.Length);
    > s.Close();
    > string base64String;
    > try
    > {
    > base64String = System.Convert.ToBase64String(binaryData, 0,
    >
    > binaryData.Length);
    > }
    > catch (System.ArgumentNullException)
    > {
    > System.Console.WriteLine("Binary data array is null.");
    > return;
    > }
    > txtGetDoc.Text = base64String;
    > } //end of if
    > } //end of private..
    >
    > Waiting for an answer...
    >
    > Thanks
    > Ipsita
     
    bruce barker, Oct 29, 2004
    #2
    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:
    3
    Views:
    3,119
    Scott Mitchell [MVP]
    Oct 29, 2004
  2. David Dundua

    Referenced DIME attachment

    David Dundua, Jul 23, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    120
    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:
    184
  4. Senthil

    DIME Attachment from Client to Server

    Senthil, Oct 6, 2003, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    270
    Scott McFadden
    Oct 8, 2003
  5. Ipsita

    How to send a DIME attachment with SOAP

    Ipsita, Oct 29, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    375
    Dan Rogers
    Nov 16, 2004
Loading...

Share This Page