Solved

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

Posted on 2014-07-30
5
153 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 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 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