Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

19 Experts available now in Live!

Get 1:1 Help Now