C # Create a lite version of IIS

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Threading;usingSystem.Net;usingSystem.IO;namespacesampleiis{//Sample IIS class    classSampleiis { Public voidStartiis () {stringURL ="http://localhost:8080/"; stringvm_id =string.            Empty; HttpListener HttpListener=NewHttpListener (); Httplistener.authenticationschemes=authenticationschemes.anonymous;            HTTPLISTENER.PREFIXES.ADD (URL); //1. Start ServerSystem.Console.WriteLine ("[{1}] [System] Start Server, Port {0} \ r \ n", URL, DateTime.Now.ToLongTimeString ());            Httplistener.start (); NewThread (NewThreadStart (Delegate            {                 while(true)                {                    //2. wating CommadSystem.Console.WriteLine ("[{0}] [System] wating Commad ... \ r \ n", DateTime.Now.ToLongTimeString ()); HttpListenerContext HttpListenerContext=Httplistener.getcontext (); //3. Receive request/do something/create VM//ceate VM and get vm_idvm_id =string. Format ("Vm_id:xiaochen-123456-{0}-{1}", DateTime.Now.ToString ("YYYYMMDDHHMMSS"), DateTime.Now.Millisecond); System.Console.WriteLine ("[{0}] [Remote] Receive request.", DateTime.Now.ToLongTimeString ()); System.Console.WriteLine ("[{0}] [Remote] Receive privillige, working ...", DateTime.Now.ToLongTimeString ()); System.Console.WriteLine ("[{0}] [Remote] {1} Create successfully!", DateTime.Now.ToLongTimeString (), vm_id); //4. Respone header/contentsHttpListenerContext.Response.StatusCode = $; HTTPLISTENERCONTEXT.RESPONSE.HEADERS.ADD (vm_id); //Header, Key-value random addHttpListenerContext.Response.ContentType ="Text/plain"; using(StreamWriter writer =NewStreamWriter (HttpListenerContext.Response.OutputStream)) {                        //Response as XMLWriter. WriteLine ("<?xml version=\ "1.0\" >"); Writer. WriteLine ("<niaoyun>"); Writer. WriteLine ("<result>{0}</result>", vm_id); Writer. WriteLine ("<message>Success</message>"); Writer. WriteLine ("<version>V1.0</version>"); Writer. WriteLine ("<time>{0}</time>", DateTime.Now.ToString ("YYYYMMDDHHMMSS")); Writer. WriteLine ("</niaoyun>"); }                    //5. EndingSystem.Console.WriteLine ("[{0}] [Remote] completed!\r\n", DateTime.Now.ToLongTimeString ()); }            })).        Start (); }    }    classProgram {Static voidMain (string[] args) {Sampleiis Siis=NewSampleiis (); Siis.        Startiis (); }    }}

C # Create a lite version of IIS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.