Answered by:
how to send pdf file through webservice.......asmx

Question
-
User442781244 posted
hi
guys
i have website(suppose A) i.e has N users.......now another website i.e B wants to send PDF file to my website i.e A's user . so how to create webmethod for this:
On internet i got this code.....but dont no this is correct or not???
what things i have to add and all things
[WebMethod] public byte[] GetPdf() { using (Stream s = new FileStream("yourFile.pdf")) { byte[] ret = new byte[s.Length]; s.Read(ret, 0, s.Length); return ret; } }
kindly suggest
Tuesday, November 26, 2013 1:25 AM
Answers
-
User-1509636757 posted
Here is a solution which contains two websites.. one is sending pdf in bytes by calling web service of a website and that website is receiving pdf file by converting bytes into physical file. You may required to debug or see as per you requirement as code is not the tested one. But, it shows what you need to do.
http://weblogs.asp.net/blogs/kaushal/PdfWebsites.zip
hope it helps./.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 27, 2013 12:53 AM
All replies
-
User-1509636757 posted
Check out this resolved thread: WebService returning pdf file : The Official Microsoft ASP.NET Forums
hope it helps./.
Tuesday, November 26, 2013 2:07 AM -
User442781244 posted
kaushal
how to check this webmethod ...working or not???
Tuesday, November 26, 2013 2:13 AM -
User516094431 posted
I already reply on below thread, just check it:
Please use this code,
[WebMethod]
public byte[] GetFile(string filename){
BinaryReader binReader = new BinaryReader(File.Open(Server.MapPath(filename), FileMode.Open, FileAccess.Read));
binReader.BaseStream.Position = 0;
byte[] binFile = binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length));
binReader.Close();
return binFile;
}Let me know if you face still error.
Also check http://forums.asp.net/t/1576851.aspx
Thanks.
Tuesday, November 26, 2013 2:13 AM -
User442781244 posted
actually i ve this requirement
i have website(suppose A) i.e has N users.......now another website i.e B wants to send PDF file to my website i.e A's user
your webmethod is fulfilling whole requiremnet or i have to add something more.kindly suggest mshoaiblibra
how to check this webmethod???
becuase on running it is asking for file name...so next what to do???
Tuesday, November 26, 2013 2:15 AM -
User1508394307 posted
On internet i got this code.....but dont no this is correct or not???No, it seems it is not what you expect. If you need a service that will accept remote call with a file in it then the service should look similar to the one explaine here
http://www.codeproject.com/Articles/22985/Upload-Any-File-Type-through-a-Web-Service
The article provides complete source code as well as the code to test.
Read it and check if this is what you want and test locally.
There are a lot of similar threads on this forum. One of them is http://forums.asp.net/t/1531194.aspx
Hope this helps.
Tuesday, November 26, 2013 2:24 AM -
User442781244 posted
smir,
i am new to webservice....so i dont knw so much..
my requirement is
website(suppose A) i.e has N users.......now another website i.e B wants to send PDF file to my website i.e A's user
so tell how to acheive thrugh which webmethod???
Tuesday, November 26, 2013 2:30 AM -
User442781244 posted
this is my requiremnet
website(suppose A) i.e has N users.......now another website i.e B wants to send PDF file to my website i.e A's user
i belong to website A......users.
so website B user told me create webservice so that they can send pdf file to my website i.e Ausers.
for this they told me create 3 webmethods:
1>list of department
2>list of user based on selection of dept
3>that sending pdf file...from website B user to website A user.
website A has login page containing:
1>dept in dropdown
2>userlist absed on selection of dept from above
3>username
4>pwd.
guys..suggest me how to acheive this that sending pdf file...from website B user to website A user.
i hope now ques si clear if not then plz let me knw
Tuesday, November 26, 2013 3:46 AM -
User1079421601 posted
Please try like this.
[WebMethod] public byte[] GetFile(string filename) { BinaryReader binReader = new BinaryReader(File.Open(Server.MapPath(filename), FileMode.Open, FileAccess.Read)); binReader.BaseStream.Position = 0; byte[] binFile = binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length)); binReader.Close(); return binFile; }
References:
- WebService returning pdf file
- File Upload with ASP.NET
- Creating and using Web Services with the .NET framework and Visual Studio.Net
- Upload Any File Type through a Web Service
Tuesday, November 26, 2013 3:56 AM -
User442781244 posted
what abt sending pdf file???kindly explain....i have posted my requiremnet and so plz explain
how to check this webmethod i.e this webmethod will be able to send pdf files????
explain my doubts
Tuesday, November 26, 2013 3:59 AM -
User-488622176 posted
- In Website A : add a WCF service with a method that receives the PDF in byte[] format
- To this WCF service : add security (http://msdn.microsoft.com/en-us/library/ff650862.aspx)
- In website B : read the PDF file (locally), call the WCF service from website A and send the PDF data
Tuesday, November 26, 2013 10:28 AM -
User442781244 posted
illeris,i have to acheive this using .asmx so suggest me in this direction....not wcf
Tuesday, November 26, 2013 11:54 PM -
User322534949 posted
BinaryReader binReader = new BinaryReader(File.Open(Server.MapPath(filename), FileMode.Open, FileAccess.Read));
what is server ? should we have any namespace or references for it??
Wednesday, November 27, 2013 12:40 AM -
User-1509636757 posted
Here is a solution which contains two websites.. one is sending pdf in bytes by calling web service of a website and that website is receiving pdf file by converting bytes into physical file. You may required to debug or see as per you requirement as code is not the tested one. But, it shows what you need to do.
http://weblogs.asp.net/blogs/kaushal/PdfWebsites.zip
hope it helps./.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 27, 2013 12:53 AM -
User442781244 posted
kaushal..
i got code...but confused what to add or not??
plz guide me.
Wednesday, November 27, 2013 5:03 AM