By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,122 Members | 1,527 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,122 IT Pros & Developers. It's quick & easy.

Problem with streaming a DIME attachment with SOAP

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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?)
Ipsita wrote:
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
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #2

P: n/a
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 [MVP]" <mi******@4guysfromrolla.com> wrote in message news:<m4*******************@newssvr21.news.prodigy .com>...
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?)
Ipsita wrote:
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

Nov 18 '05 #3

P: n/a
Ipsita wrote:
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 [MVP]" <mi******@4guysfromrolla.com> wrote in message news:<m4*******************@newssvr21.news.prodigy .com>...
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?)
Ipsita wrote:
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
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.