Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2004

Tip: Looking for answers? Try searching our database.

How to send a DIME attachment with SOAP

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ipsita - 29 Oct 2004 03:19 GMT
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 - 16 Nov 2004 01:43 GMT
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: ipsita.mohanty@gmail.com (Ipsita)
>Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
[quoted text clipped - 7 lines]
>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: groups-abuse@google.com
>NNTP-Posting-Date: Fri, 29 Oct 2004 02:19:21 +0000 (UTC)
>Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.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.webservices:26306
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
>
[quoted text clipped - 55 lines]
>Thanks
>Ipsita

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.