Problem with streaming a DIME attachment with SOAP

I

Ipsita

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
 
S

Scott Mitchell [MVP]

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?)

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
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
I

Ipsita

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 said:
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?)

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
 
S

Scott Mitchell [MVP]

Ipsita said:
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 said:
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?)

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
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top