Answered by:
file attachment in Web Service

Question
-
Hi,
I'm using .NETCF 2.0 and OPENNETCF for Security header.
I was able to communicate with my server without attachment but I need to attach media files sometimes.
I have no clue how to do in .NETCF.
Can anyone help me on this?
Any examples or solutions?
Thanks in advance.
Duk.Thursday, November 5, 2009 7:38 PM
Answers
-
Hi,
I'm using .NETCF 2.0 and OPENNETCF for Security header.
I was able to communicate with my server without attachment but I need to attach media files sometimes.
I have no clue how to do in .NETCF.
Can anyone help me on this?
Any examples or solutions?
Thanks in advance.
Duk.
Hi Duk,
In Web service there is no direct way to attached file for uploading your destination server. so you have use Byte Array of file and then send over the server and server must be understand which file format convert in your actual format. For uploading file your file can use in your web service method Byte Array.
Q: How to convert file into Byte Array ?
Solution : See below code snippet.
private byte[] GetFileByteArray(string filename) { FileStream oFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); // Create a byte array of file size. byte[] FileByteArrayData = new byte[oFileStream.Length]; //Read file in bytes from stream into the byte array oFileStream.Read(FileByteArrayData, 0, System.Convert.ToInt32(oFileStream.Length)); //Close the File Stream oFileStream.Close(); return FileByteArrayData; //return the byte data }
This above method return the file's Byte array.
Another one more way you can use uploading file over the server using HttpWebRequest & HttpWebResponse please see this Thread (which is already discussed) for uploading file using HttpWebRequest & HttpWebResponse.
Hope this may be help.
If you find my post is helpful for you then mark as a answer.- Proposed as answer by Christian Resma Helle Saturday, November 7, 2009 9:32 PM
- Marked as answer by ZHE ZHAO Thursday, November 12, 2009 3:51 AM
Saturday, November 7, 2009 9:14 AM
All replies
-
From what I understand, you want to return a file from a web service, correct?
You should be able to do this by returning stream's contents as a byte array from the web service and write it to a file in the consuming clientFriday, November 6, 2009 10:32 AM -
Hi Christian,
What I want is that I want to attach a file in my web service call from client that I'm going to implement, but not from a server.
Thanks,
DukFriday, November 6, 2009 3:37 PM -
Hi,
Are you proposing to be able to just send up an attachment without the server having to handle this?
As Christian suggests, you can pass a byte array as a parameter back to the server and then the server can write this byte array to a file.
Thanks
Paul Diston
http://www.smartmobiledevice.co.uk/Saturday, November 7, 2009 8:08 AM -
Hi,
I'm using .NETCF 2.0 and OPENNETCF for Security header.
I was able to communicate with my server without attachment but I need to attach media files sometimes.
I have no clue how to do in .NETCF.
Can anyone help me on this?
Any examples or solutions?
Thanks in advance.
Duk.
Hi Duk,
In Web service there is no direct way to attached file for uploading your destination server. so you have use Byte Array of file and then send over the server and server must be understand which file format convert in your actual format. For uploading file your file can use in your web service method Byte Array.
Q: How to convert file into Byte Array ?
Solution : See below code snippet.
private byte[] GetFileByteArray(string filename) { FileStream oFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); // Create a byte array of file size. byte[] FileByteArrayData = new byte[oFileStream.Length]; //Read file in bytes from stream into the byte array oFileStream.Read(FileByteArrayData, 0, System.Convert.ToInt32(oFileStream.Length)); //Close the File Stream oFileStream.Close(); return FileByteArrayData; //return the byte data }
This above method return the file's Byte array.
Another one more way you can use uploading file over the server using HttpWebRequest & HttpWebResponse please see this Thread (which is already discussed) for uploading file using HttpWebRequest & HttpWebResponse.
Hope this may be help.
If you find my post is helpful for you then mark as a answer.- Proposed as answer by Christian Resma Helle Saturday, November 7, 2009 9:32 PM
- Marked as answer by ZHE ZHAO Thursday, November 12, 2009 3:51 AM
Saturday, November 7, 2009 9:14 AM -
I have a question regarding FileStream();
FileStream(filename, FileMode.Open, FileAccess.Read)
How to give filename?
My code is reading full path like "\My Documents\My Pictures\xxx.jpg".
Is this how I am supposed to give?
Thanks,
DukFriday, November 13, 2009 9:56 PM -
I have a question regarding FileStream();
FileStream(filename, FileMode.Open, FileAccess.Read)
How to give filename?
My code is reading full path like "\My Documents\My Pictures\xxx.jpg".
Is this how I am supposed to give?
Thanks,
Duk
Hi Duk,
You can use full path as a filename.
see below code snippet for the same.
filename = @"\My Documents\My Pictures\xxx.jpg";
Hope this may be help.
If you find my post is helpful for you then mark as a answer.Sunday, November 15, 2009 9:22 AM -
Thanks for your answer.
Then, can I do like this?
string
fileName = @this.f_name.Text;
Actually "this.f_name.Text" is holding full path of the file.
Thanks,
Duk.Monday, November 16, 2009 3:42 PM