Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to send a DIME attachment with SOAP

Reply
Thread Tools

How to send a DIME attachment with SOAP

 
 
Ipsita
Guest
Posts: n/a
 
      10-29-2004
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
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      10-29-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send a DIME attachment with SOAP Ipsita ASP .Net Web Services 1 11-16-2004 01:43 AM
Problem with streaming a DIME attachment with SOAP Ipsita ASP .Net 3 10-29-2004 04:50 AM
DIME Attachment from Client to Server Senthil ASP .Net Web Services 2 10-08-2003 04:22 PM
SoapExtensions, DIME Attachment and Pipes Oleg ASP .Net Web Services 0 09-30-2003 07:55 PM
Referenced DIME attachment David Dundua ASP .Net Web Services 0 07-23-2003 02:55 PM



Advertisments