473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with streaming a DIME attachment with SOAP

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
3 5088
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Espen Sletteng | last post by:
Hello all, I want to create a .NET-based web service that can accept dime-based attachments from a java (Axis)-based client. I have searched for examples that look like this scenario, but...
4
by: Scott, Killer of all Ninjas | last post by:
It seems incredulous to me that it is so difficult to write the contents of a memory stream to a file. I'm certain that I'm missing something simple. I am retrieving a memory stream from a DIME...
0
by: Drew | last post by:
Hello - I am trying to write a C# client that takes in a DIME attachment. The WSDL was generated with a WSDL generator using the third party software form systinet. My question is how do I...
1
by: Eirik Brattbakk | last post by:
Hi I have some problems accessing a soap service made in c# using an ATL/MFC client over SSL. I have tried both CSoapMSXMLInetClient and CSoapWininetClient as template arguments with my stub...
1
by: Ipsita | last post by:
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...
0
by: saliwen | last post by:
Can WSE2.0 implements SOAP Attachments of W3C for interoperations ?
0
by: munish | last post by:
Hi, I am trying to send a tiff file which contains multiple pages/frames as a dime attachment. When I am saving the file on the server only the first page of image gets saved. Any Ideasv how to...
0
by: talkie1 | last post by:
Hi, i work with Visual Studio 2003 und i have a C# - WebApplication in which i make a stream from a *.doc file! Code WebForm1: ... DimeAttachment attachment = new...
1
by: Matt B | last post by:
Hi all, This problem is close to driving me insane. Basically, I'm trying to use DIME to add an attachment to a SOAP message and send it to the web server. The WSE 2.0 toolkit is installed,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.