exposing zip file via Web service

Sep 18, 2009 at 10:18 AM

I noticed the ZipFile is not serializable.

We would like to expose the zipfile via webservice to a client, just wondering if you happen to any suggestions/workaround to achieve this.

Thanks

NP

Coordinator
Sep 18, 2009 at 8:03 PM

What do you mean by "expose the zipfile"?

what exactly is involved in exposing a zipfile to a client via a web service?

Sep 19, 2009 at 6:58 AM

Sorry about the confusion. I meant to say sending the zip file via a web service.

If i try to serialize the zip file i get an exception indicating it is not serializable.

Thanks

NP

Coordinator
Sep 19, 2009 at 7:11 AM

If the zipfile is in memory, why don't you send it as a stream? 

If the zipfile is on the filesystem, you can just read the file and send it as you would any file.

I don't understand why you want to send a ZIpFile object.

Can you explain your scenario again please?  what is it that you really want to do?  Are you trying only to send a compressed data stream across the wire?

if that's the case why a zipfile?  Why not just use a DeflateStream or ZlibStream or GZipStream ?

 

Sep 21, 2009 at 4:30 AM
Cheeso wrote:

If the zipfile is in memory, why don't you send it as a stream? 

If the zipfile is on the filesystem, you can just read the file and send it as you would any file.

I don't understand why you want to send a ZIpFile object.

Can you explain your scenario again please?  what is it that you really want to do?  Are you trying only to send a compressed data stream across the wire?

if that's the case why a zipfile?  Why not just use a DeflateStream or ZlibStream or GZipStream ?

 

Thanks Cheeso for that.

>>Are you trying only to send a compressed data stream across the wire?

Yes, this is exactly what i am trying to do as the zip file may contain a large number of files.

To be able to send in a web service the objects need to be serializable.

I will look into the streams as you said and see if it would help.

Thanks

NP

 

Sep 21, 2009 at 7:20 PM
pathurun wrote:
Cheeso wrote:

If the zipfile is in memory, why don't you send it as a stream? 

If the zipfile is on the filesystem, you can just read the file and send it as you would any file.

I don't understand why you want to send a ZIpFile object.

Can you explain your scenario again please?  what is it that you really want to do?  Are you trying only to send a compressed data stream across the wire?

if that's the case why a zipfile?  Why not just use a DeflateStream or ZlibStream or GZipStream ?

 

Thanks Cheeso for that.

>>Are you trying only to send a compressed data stream across the wire?

Yes, this is exactly what i am trying to do as the zip file may contain a large number of files.

To be able to send in a web service the objects need to be serializable.

I will look into the streams as you said and see if it would help.

Thanks

NP

 

 funny this is almost what i am doing from the sound of it.

here are some snips of code:

on hh that gets a zip:

 

<font size="1">

 

</font>

string Base64Text = string.Empty;
byte[] Raw = { 0, 0, 0, 0 };

 

<font size="1">

Base64Text = Srv.GetUpdateInfo(

</font>

);  // web method call
Raw = Convert.FromBase64String(Base64Text);
FileStream Fs = File.Create("\\FlashDisk\\Up\\Update.Zip", Raw.Length / 8);
Fs.Write(Raw, 0, Raw.Length);
Fs.Flush();
Fs.Close();
data is now on hh flash disk as a zip file.

 

<font size="1">

On Server to send data:

</font>

[WebMethod]
public string GetUpdate() {
string
datastring = string.Empty;
datastring = Convert.ToBase64String(
System.IO.
File.ReadAllBytes(
this.Server.MapPath(
"~/App_Data/Update." + WebConfigurationManager.AppSettings["CurrentVersion"] + ".zip")
),
Base64FormattingOptions.InsertLineBreaks);

 

return datastring;
}

<font size="1"><font size="1"><font size="1"><font size="1">

thats one way to do this for a file on disk to download to a hh device.

</font></font></font></font>

<font size="1"><font size="1"><font size="1">

 

</font></font></font><font size="1"><font size="1">

 

</font></font><font size="1">

 

</font>

 

Coordinator
Sep 21, 2009 at 8:53 PM

If you are transmitting a large file, you might want to look into streaming the file content.

 

Coordinator
Sep 21, 2009 at 9:00 PM

I haven't done this, but if I were building it, I would first try this:

define a service contract that allowed the client to provide a stream to the server.  The stream on the client might be a filestream or a memory stream.  The server would then produce the zip file and then save it to the stream provided by the client.  The client can then do what it wants with the zip content.

If that does not work, for whatever reason, a simple file transfer approach would also work.  Here again I'd use streaming though, to avoid the requirement that all zip content be kept in memory.

if you're not concerned about keeping all the content in memory at one time , then use the approach given above, by figuerres, where the content is sent all as one large base64 string.  Encoding it that way will inflate the data on the wire significantly, so I'd recommend that only for small zip files, and when performance is not a concern.

 

 

Sep 22, 2009 at 9:30 AM

Thanks very much for your input Cheeso and Figurres. I will give it a try and see how it works.

Thanks

NP

Sep 24, 2009 at 9:51 PM
Cheeso wrote:

I haven't done this, but if I were building it, I would first try this:

define a service contract that allowed the client to provide a stream to the server.  The stream on the client might be a filestream or a memory stream.  The server would then produce the zip file and then save it to the stream provided by the client.  The client can then do what it wants with the zip content.

If that does not work, for whatever reason, a simple file transfer approach would also work.  Here again I'd use streaming though, to avoid the requirement that all zip content be kept in memory.

if you're not concerned about keeping all the content in memory at one time , then use the approach given above, by figuerres, where the content is sent all as one large base64 string.  Encoding it that way will inflate the data on the wire significantly, so I'd recommend that only for small zip files, and when performance is not a concern.

 

 

 i am fairly sure that for an asmx or wcf over http that http will send the data in chunks as http packets, i guess the issues would be the use of .ReadAllBytes ....   one could read a chunk and send it with a seq number... then the reciving side could get 1, get 2, get 3 and so on....

the .net cf limits a lot of what we can do with wcf and stuff..... I *WISH* they had put in support for WCF over sockets with Binary serialization!  I have about 80 devices that all upload data every day.... https soap is kinda big chunks.