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