How to send a DIME attachment with SOAP

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default How to send a DIME attachment with SOAP

    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 Guest

  2. Similar Questions and Discussions

    1. Dime Attachment from client
      Hi, Just install runtime WSE instead. -- ______________________________ With best wishes, Arthur Nesterovsky Please visit my home page:...
    2. DIME Attachment from Client to Server
      hi, I need to write an application which needs to transfer a binary file from client to server. I will be able to send it as DIME attachment along...
    3. SoapExtensions, DIME Attachment and Pipes
      Does anybody know a good C# replacement for java.io.PipedInputStream, PipedOutputStream? The reason I'm asking is sometimes I need transfer...
    4. Send a Dataset as a Dime Attachment
      Hello, Thanks very much for posting here. After reviewing the question, I think you could just return dataset in the web method and then use it...
    5. Referenced DIME attachment
      All, I am using .NET framework 1.WSE 1sp1. I am trying to send referenced DIME attachment (ie using href tag) from Apache Axis 1.1 client. I get...
  3. #2

    Default RE: How to send a DIME attachment with SOAP

    Hi,

    I think the issue is you are trying to convert a Word document to a text
    string. To quote the little boy with the spoon in "The Matrix" - "That's
    impossible.".

    To read a word document on the client side, you could write the stream as
    received to an appropriately named file, and then invoke word. Otherwise,
    you might try to load the stream into an XMLDocument class - most word
    documents these days are XML, but older versions are not. From there you
    might be able to find the string you are looking for.

    In short, to display text in a text box, you'll need to make sure you're
    sending text that is suitble for display in a text box. Most binary files
    are not.

    Sorry if this isn't the answer you were seeking,

    Regards

    Dan Rogers
    Microsoft Corporation
    --------------------
    >From: [email]ipsita.mohanty@gmail.com[/email] (Ipsita)
    >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
    >Subject: How to send a DIME attachment with SOAP
    >Date: 28 Oct 2004 19:19:20 -0700
    >Organization: [url]http://groups.google.com[/url]
    >Lines: 57
    >Message-ID: <ef1b2b65.0410281819.2c2f9be5@posting.google.com >
    >NNTP-Posting-Host: 24.6.231.155
    >Content-Type: text/plain; charset=ISO-8859-1
    >Content-Transfer-Encoding: 8bit
    >X-Trace: posting.google.com 1099016361 5961 127.0.0.1 (29 Oct 2004
    02:19:21 GMT)
    >X-Complaints-To: [email]groups-abuse@google.com[/email]
    >NNTP-Posting-Date: Fri, 29 Oct 2004 02:19:21 +0000 (UTC)
    >Path:
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFT NGP08.phx.gbl!news-out.cwi
    x.com!newsfeed.cwix.com!border1.nntp.dca.giganews. com!nntp.giganews.com!news
    glorb.com!postnews1.google.com!not-for-mail
    >Xref: cpmsftngxa10.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webservic es:26306
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    >
    >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
    >
    Dan Rogers Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139