Click here to Skip to main content
12,350,728 members (23,817 online)
Click here to Skip to main content

Stats

17.8K views
252 downloads
11 bookmarked
Posted

XML Serialization and Firewalls

, 7 Jul 2007
A sample on transmitting binary content over firewalls
Serial Downloader - CodeProject
SDWebService
App_Code
Properties
SDWinClient
bin
Debug
SDWinClient.exe
SDWinClient.pdb
SDWinClient.vshost.exe
obj
Debug
SalvatoreCarlos.CodeProject.SerialDownloader.SDWinClient.Form1.resources
SDWinClient.csproj.GenerateResource.Cache
SDWinClient.exe
SDWinClient.pdb
SiProd.Applications.SerialDownloader.SDWinClient.Properties.Resources.resources
TempPE
Properties.Resources.Designer.cs.dll
Web References.localhost.Reference.cs.dll
Properties
SDWinClient.csproj.user
Web References
localhost
Reference.map
SerialDownloader.disco
SerialDownloader.wsdl
Serial Downloader - CodeProject.suo
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

Share

About the Author

carlosmsr
Architect
Argentina Argentina
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 7 Jul 2007
Article Copyright 2007 by carlosmsr
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid