Diluksha's profileDiluksha's spacePhotosBlogListsMore Tools Help

Blog


    October 09

    XML Serialization with .Net

     

    What is XML Serialization?

    Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an object and transport it over the Internet using HTTP between a client and a server. On the other end, deserialization reconstructs the object from the stream.

    And also serialization of XML to common language runtime objects enables one to convert XML documents into a form where they are easier to process using conventional programming languages.

    Sample with C# .Net

    1. Create a console application

    2. Add new XML schema to the project

    clip_image002

    3. Add new Complex type and an Element type to the schema.

    clip_image004

    4. Run following command in Visual Studio Command Prompt to convert created XML schema to the C# class.

    >xsd.exe /c Person.xsd

    This will create a C# file named “Person.cs” inside the solution folder. Add the created C# file into the solution.

    5. xsd.exe is a utility to generate schema or class files from given source. It is included with the .NET Framework. There are three main uses for xsd.exe.

    · xsd.exe <schema>.xsd which will create source code for the appropriate class to de-serialize your object.

    · xsd.exe <assembly>.dll|.exe is used to read the code and generate a schema (.xsd) file for you.

    · xsd.exe <instance>.xml|.xdr which will try to infer an .xsd file which you can then use to create an appropriate class

    6. Code sample to do a serialization

    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Xml.Serialization;
    using System.IO;

    namespace SerializationSample
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Serializing..
                Person person = new Person();
                person.id = 100;
                person.name = "Diluksha Geeganage";
                person.address = "Sri Lanka";
                person.age = 27;

                XmlSerializer xmlS = new XmlSerializer(typeof(Person));
                FileStream file = new FileStream(@"Persons.xml", FileMode.Create, FileAccess.Write);
                xmlS.Serialize(file, person);

                Console.WriteLine("Serializing Completed");
                Console.Read();

                file.Close();
            }
        }
    }

    7. Code sample to do a deserialization

    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Xml.Serialization;
    using System.IO;

    namespace SerializationSample
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Deserializing..
                Person objPerson;

                XmlSerializer xmlD = new XmlSerializer(typeof(Person));
                FileStream fileD = new FileStream(@"Persons.xml", FileMode.Open, FileAccess.Read);

                objPerson = (Person)xmlD.Deserialize(fileD);
                Console.WriteLine("ID {0} Name {1} Address {2} Age {3}", objPerson.id, objPerson.name, objPerson.address, objPerson.age);
                Console.Read();

                fileD.Close();
            }
        }
    }

     

     

    October 06

    Anonymous proxy server


    Anonymous proxy server is a routing communications between your computer and the Internet that can hide or mask your unique address to prevent unauthorized access to your computer over the Internet. An address is your computer's digital ID while you are online. By masking this, it helps prevent other web sites that can gain access and gather personal information about you through your unique address. Any anonymous proxy server can hide your online ID by using its own address in place of yours in every outgoing request. It helps protect your privacy while you are online.

    You can use these proxy severs to gain access to unblock sites, as well as any other site.

    They are three basic approaches for anonymous surfing through the Net:

    • Web

    Web proxy work through the Web (i.e. cgi proxy or php proxy). You just need to visit server and surf through Web based proxy. Your IP address is anonymous and invisible to any site that you visit because you surf through web proxy that is located on certain server. Web proxies act as anonymous proxy server. You don't need to install or configure anything.

    • Direct

    Direct require the surfer to modify settings in the browser so that the browser specifically accesses the proxy server providing the anonymous services. Some of these proxies require that the surfer make the changes manually to the browser while others will modify the settings with the expressed permission of the surfer.

    • Client

    Client based applications software that must be installed on user PC. They act as a local proxy server on your PC and allow you to surf the Web anonymous protecting your privacy. There are many applications that allow you to surf anonymously i.e. JAP, Tor, GhostSurf, Rutschomat, A4proxy, Multiproxy, ProxyRama etc. Some clients provide their own severs for surfing i.e. JAP, Tor, GhostSurf.