Click here to Skip to main content
15,891,943 members
Articles / Web Development / ASP.NET

XML Serialization and Firewalls

Rate me:
Please Sign up or sign in to vote.
2.13/5 (5 votes)
7 Jul 20072 min read 28.1K   306   12  
A sample on transmitting binary content over firewalls
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.IO;
using System.Net;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;

namespace SalvatoreCarlos.CodeProject.SerialDownloader.WebService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class SDWebService : System.Web.Services.WebService
    {

        [WebMethod]
        public string GetBase64StringFromResource(String URI)
        {
            string result = string.Empty;
            
            try
            {
                WebRequest request = WebRequest.Create(URI);
                WebResponse response = request.GetResponse();

                Stream respStrm = response.GetResponseStream();
                int length = (int)response.ContentLength;

                byte[] bytes = new byte[length];

                int numBytesRead = 0;

                while (length > 0)
                {
                    int n = respStrm.Read(bytes, numBytesRead, length);
                    if (n == 0)
                        break;
                    numBytesRead += n;
                    length -= n;
                }
                respStrm.Close();

                result = Convert.ToBase64String(bytes);
            }
            catch (Exception e)
            {
                return e.ToString();
            }
            return result;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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


Written By
Architect Carlos Salvatore
Argentina Argentina
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This is a Organisation (No members)


Comments and Discussions