?
Solved

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

Posted on 2014-07-30
5
Medium Priority
?
157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 total points
ID: 40392019
The value of the FileSize variable would be the length of the byte[] array Buffer (Buffer.Length).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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 …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 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