Solved

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

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 30
TimeZone, day light savings, Sql server, asp.net 6 37
JSON Deserialize issue 6 26
SSIS Start 2 20
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

791 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