Project requirements
In the previous project, WCF was used. netTcpBinding was selected as the binding mode, and the Console mode was selected as the host. The following two advantages are taken into account:
- Easy Management of host Lifecycle
- Improve Service Performance
However, there are many problems in the actual development process, such:
- When debugging a project, you must start the console to provide services.
- After remote deployment, the system cannot provide services normally once it is logged out.
- An exception in the console causes the service instance to crash and the new instance cannot be started to provide services in time
After several months of practice, we decided to transform the WCF Service and change the host to IIS, so that we could promptly handle the problem that service process crashes and new service processes could not be generated, I made a Demo to try to reconstruct the host.
IIS6.0 System Analysis
There is a detailed article on msdn about how to host wcf to IIS:
The http://msdn.microsoft.com/zh-cn/magazine/cc163357.aspx uses WAS to extend the WCF Service outside of HTTP
Here is a brief introduction:
The IIS 6.0 system has two basic components: Listeners and working processes:
The listener process is implemented by the w3svc service. It monitors the requests received by the host and submits the requests to the processing process of the response according to the binding configuration, if the request for the aspx file is submitted to aspnet_isapi.dll for processing
A work process is a lightweight executable file. When it starts to respond to an activation request, it first loads a simple unmanaged filling program DLL (w3wphost. dll) to support w3svc communication with the worker process. The filling program is also responsible for loading aspnet_isapi.dll. This file will implement interfaces between the managed components of ASP. NET and the unmanaged components of IIS. Then you can output the response data to the requester normally.
IIS7.0's support for WCF
Let's take a look at this figure,
In IIS 6.0, the w3svc service actually undertakes dual tasks. It is registered in http. sys and is the direct receiver of incoming HTTP Communication. Therefore, it acts as an HTTP listener. It also has a process activation component, which is responsible for correctly starting a new w3wp instance and dispatching requests. In IIS 7.0, these two responsibilities are reconstructed to different Windows NT services. The w3svc process retains its role as an HTTP listener, but the component responsible for configuration and process activation is counted as one of the factors in WAS. WAS includes three parts: configuration Manager, Process Manager, and unmanaged listener adapter interface.
TCP listening is used here. To support TCP communication in IIS7, We need to configure several items
WCF Activation
Windows Process activation Service
Tcp support also needs to be configured in IIS7. First, ensure that the framework support for. NET4.0 is installed after IIS7 is enabled.
Configure the website binding and add nettcp. The default port is 808. If you want to host a service for Silverlight access, set it to 4502 or 45 **, which corresponds to the policy file.
Add nettcp in Advanced Settings
Well, here we can configure IIS7 to support TCP communication. Let's first look at the Demo code structure.
The project of the WCF Service Host in the console
The Demo solution includes a console host and a WCF class library.
The service is very simple. It provides a plus operation service:
public class Add:IAdd { public int GetResult(int numberA, int numberB) { return numberA + numberB; } }
The Host code is also very simple to start the service.
static void Main(string[] args) { var host = new System.ServiceModel.ServiceHost(typeof(WCFLib.Add)); host.Open(); Console.WriteLine("service opened.."); Console.Read(); }
The configuration file specifies the service address and Endpoint information:
Okay. After a service is developed, it can run normally. Next we will introduce how to transfer this HOST to IIS.
Article index: WCF Service reconstruction real-recorded (on) WCF Service reconstruction real-recorded (medium)
Demo File Download: http://files.cnblogs.com/wengyuli/WCFHostChange.rar