C #. net implement web server (web Service) based on Http)

Source: Internet
Author: User
Tags small web server

What is web server?

Baidu encyclopedia explains this:

Web Server WEB Server WWW

The Web server can parse the HTTP protocol (handles. When the Web server receives an HTTP request, it returns an HTTP response (response), for example, sending back an HTML page. In order to process a request, the Web server can respond to a static page or image, perform a page Jump (redirect), or send a dynamic response (dynamic response) to some other programs, such as CGI scripts, JSP (assumerver Pages) scripts, servlets, ASP (Active Server Pages) scripts, server-side) javaScript, or some other server-side technologies. Regardless of their purpose, these server-side programs usually generate an HTML response (response) for browsers to browse.

In general, Web server transfer (serves) pages allow browsers to browse. However, the application server provides client applications with the call method ). Specifically, you can say that the Web server specifically processes HTTP requests, but the application server uses many protocols to provide business logic for applications ). Common web Server

We often use web services such as IIS and tomcat. During network communication, we will also use socket, or even implement HTTP Communication Based on socket, but let's take a look at the simpler implementation.

What can we do?

IIS is very powerful and has complete functions. Our goal is not to make a web server that is the same as it. It serves our development and architecture based on this concept.

Features and usage:

For example, when we need to communicate with multiple applications in our software.

Dedicated functions bring higher efficiency. For example, we only process the display of a certain page. We have seen the router Management page in the route, that is, a lightweight small web server implementation, which can not be placed in windows + iis;

Embedded windows applications. For example, we want to embed webBrower in winform to use it for some applications.

  

Our implementation

HttpListener Class Based on. net FrameworkTo process the http protocol, we only need to write a processing class based on it.

            = = Thread( ThreadStart(   (====  (request.HttpMethod ==   (request.HttpMethod ==              +[] buffer = Encoding.UTF8.GetBytes(=   +[] res = Encoding.UTF8.GetBytes(

How to use it?

1. Write a class that inherits from the Servlet class and implement the specific business logic here.

2. Copy the code in the main method and start httpListener in a proper way.

 

Reference: http://wenku.baidu.com/link? Url = Response

 

Http://msdn.microsoft.com/zh-cn/library/system.net.httplistener (v = vs.110). aspx

Related Article

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.