Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem with streaming a DIME attachment with SOAP

Reply
Thread Tools

Problem with streaming a DIME attachment with SOAP

 
 
Ipsita
Guest
Posts: n/a
 
      10-27-2004
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
 
Reply With Quote
 
 
 
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      10-27-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
Reply With Quote
 
 
 
 
Ipsita
Guest
Posts: n/a
 
      10-28-2004
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]" <(E-Mail Removed)> wrote in message news:<m4Tfd.35590$(E-Mail Removed) .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

 
Reply With Quote
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      10-29-2004
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]" <(E-Mail Removed)> wrote in message news:<m4Tfd.35590$(E-Mail Removed) .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
(E-Mail Removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
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
WSE 2.0 DIME Streaming Problem David Talbot ASP .Net Web Services 1 08-03-2005 08:21 PM
How to send a DIME attachment with SOAP Ipsita ASP .Net Web Services 1 11-16-2004 01:43 AM
How to send a DIME attachment with SOAP Ipsita ASP .Net 1 10-29-2004 04:45 PM
Problem of using apache soap to consume WSE 2.0 soap attachment Mullin Yu ASP .Net Web Services 0 10-08-2003 08:09 AM



Advertisments