Self-hosted by the WCF Service, and hosted by the wcf Service

Source: Internet
Author: User

Self-hosted by the WCF Service, and hosted by the wcf Service
The boarding mode of the WCF Service is a flexible operation that can be hosted in various processes. Common boarding methods include: the IIS service, Windows Service, Winform program, and console program are hosted to run the WCF Service and provide convenient and efficient service calls for callers. This section describes a common boarding Method for WCF, namely, the IIS service. This method is the most convenient, and is widely used because services can run automatically only when IIS is run. To create an IIS host mode, you only need to add a WCF Service Application in the solution to generate this service module.
Host the WCF Service to another process: (for example, console applications)

1. Create a solution: Add a WCF Service Library Project

Modify configuration items:
<? Xml version = "1.0" encoding = "UTF-8"?> <Configuration> <system. web> <compilation debug = "true"/> </system. web> <! -- When deploying a service library project, you must add the configuration file content to the app. config file of the host. System. Configuration does not support database Configuration files. --> <System. serviceModel> <services> <service name = "WcfService. Library1.Service1"> 

Add console applications, introduce WcfService. Library1 references, and add using System. ServiceModel; library file references. Copy App. config in WcfService. Library1 to the application on the console. Modify attribute to always copy

Using System; using System. collections. generic; using System. linq; using System. serviceModel; using System. serviceModel. channels; using System. serviceModel. description; using System. text; using WcfService. library1; namespace WcfTest. demo2 {class Program {static void Main (string [] args) {CoreConfigOpen () ;}/// <summary> /// configure the App through addition. config enable the WCF Service // </summary> static void CoreConfigOpen () {try {ServiceHost selfHost = new ServiceHost (typeof (WcfService. library1.Service1); selfHost. open (); Console. writeLine ("host to the console application, by loading the App. config to enable the WCF Service "); Console. readLine ();} catch (Exception ex) {Console. writeLine ("CoreCodeOpen Error:" + ex. message );}}}}

Run the project as an administrator.

In the browser address bar, enter the url of baseAddress in the configuration file.

You can see that the service is hosted successfully, and you can reference and develop the service based on the link above. In this way, the host of the console application is implemented. The same is true for windows Services and other processes. The above is based on the configuration items in the configuration file, you can also achieve boarding in other processes in the form of pure code.

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.