Solved

Create a webservice that convert a file and return the file with the new format

Posted on 2014-07-30
5
133 Views
Last Modified: 2015-06-09
Hello.

I need some help with an webservice.

Today I have written an application that takes a pdf file, extract all coordinates for the text and than convert the pdf file to a jpg picture.  

Now I would like to create a webservice that does that.

Ie. From my client I want to post a pdf file, and I want to get back a jpg file
and a TList that contains the coordinates of all texts.

So the thing I need help with here is
1. How to upload a file to a webservice and retrun antother file?
2. I also want to return a list.

Can someone help me out here or give me some good examples.

One comment that's important her,  I don't want to use a physical file on the webservice,.
The code I will use for converting the document is a com object that has
a function LoadFromVariant   and SaveToVariant
that I can use  like:  
MyObject.LoadFromVariant(MyByteArray);
MyObject.ConvertToPdf();
AnotherByteArray = MyObject.SaveToVariant();
0
Comment
Question by:pucko73
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 40229811
You cannot use a file as a parameter to a web service method.  Web services can only deal with simple types (float, int, date, string, boolean, byte, array) or classes composed of simple types.

The user will need some sort of "client" that calls the web service.  The simplest way to implement this is to create two components
A page (ASPX) that will prompt the user for the file and upload it to the server
A Web Service (ASMX) that takes a byte array as a parameter and returns a byte array

When the ASPX page receives the file, it will convert it to a byte array and call the web service and return  the byte array, then send back to the client the byte array in the response.

NOTE:  A web service is limited to 4MB files by default.  It can be changed like this:  http://msdn.microsoft.com/en-us/library/aa528822.aspx

You may be able to not have a web service at all if you implement a ASPX page.  The code behind of the page can call your API directly without having to call the web service.

If you do not or cannot have a web page, then the client application will have to call the web service.
0
 

Author Comment

by:pucko73
ID: 40229827
The biggest problem I seem to have is how to get the filedata back from the webservice on the client side.

How can I retrieve the Bytes[] thing on the client side?
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 40247018
What is your "client" side?  

If the client is a program (For example a C# or VB.net WinForms) application, then you can receive the array of bytes from the web service and write it to a file.

If the client is a web page, then I already described it.  You would write the array of bytes to the response.  Something like this:
Response.ContentType = "image/jpeg";
Response.OutputStream.Write(Buffer, 0, FileSize);
Response.Flush();

Open in new window

0
 

Author Comment

by:pucko73
ID: 40391470
How do I know the size?
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
ID: 40392019
The value of the FileSize variable would be the length of the byte[] array Buffer (Buffer.Length).
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now