Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

XML Serialization and Firewalls

2.13/5 (5 votes)
7 Jul 20072 min read 1   306  
A sample on transmitting binary content over firewalls
Screenshot - SOAPTx.gif

Introduction

This solution is composed with a Webservice that works as a proxy (it receives the request, converts the content into a format that can travel through the firewall) and a client that receives the answer and converts it back to the original format.

Base64 strings are a common solution to encode binary content for transmission over networks. Where Local networks have restricted access to the Internet (usually Proxy servers and Firewalls block requests based on its content or response headers), this may let you transmit binary files with the only need of XML content allowed.

Background

Basic experience on Webservices could help a little.

Using the Code

This article will be crystal clear for anyone with a little bit of experience in C# and Webservices. No special implementation of SOAP is used and webservices are not essential for this solution. Many other ways of transmitting the base64 string could be implemented, although webservice seems to be the easiest way.

The Windows client is coded with a reference to the webservice hosted in the local host. This way the solution can be built quickly and easily, but you probably would like to point it to a webserver hosted outside the LAN where it wouldn't be blocked by the same firewall that blocks your browser.

Core Concepts

The core of the solution is the encoding of the binary content into the base64 string.

C#
string base64string = Convert.ToBase64String(contentBytes);

The string result of this encoding will then be converted back to a bytes array from which the binary content could be rebuilt.

C#
byte[] contentBytes = Convert.FromBase64String(base64string);

Service Implementation

The webservice has only one method with the following structure:

C#
public string GetBase64StringFromResource(String URI)
{
    //    1. Retrieve at the webserver the file pointed by the URI
    //    2. Convert the content of the file to a byte array
    //    3. Encode the byte array as a base64 string
    //    4. Return the string
}

Running the Client

Just select the folder where you want to save your downloaded file and type the URI for the file you want to download (e.g.: http://yourhost.com/simpleApp.exe).

Notes

As this solution involves a proxy for the request (the webservice), this means that characteristics of the proxy will impact in the system performance (connection speed, process stability, response times, etc.).

Pendings

This is a very basic implementation. Currently it will present limitations on the size of the file to be retrieved (the max size in bytes should be the max value for an int value: 2,147,483,648).

I haven't coded any support for progress notification or exception handling.

There is no support for transmitting user credentials to authenticate at the webserver or at the host of the resource.

History

  • 7th July, 2007: Initial post

If feedback is provided or support requested, I'll keep working on this sample application.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here