WCF self-managed

Source: Internet
Author: User

1. About the host)

We generally create IIS as the host, so the projects we create in vs2008 are all hosted by IIS, as shown in. About IIS hosting, previousArticleI have already made it very clear.

 

However, there is another hosting method called self-hosting ).

To put it bluntly, the client and service share a process. To put it bluntly, the client project and service project are combined into one. For example, this demo:

C: \ Users \ baoj \ Documents ents \ Visual Studio 2008 \ projects \ wcfsolution.

The demo contains three files, contract. CS and App. config, which constitute the service. The former includes the contract and its implementation, and the latter includes the endpoint of the service. Please download the aboveCodeAnd refer to the corresponding file.

In program. CS, It is a client. Let's take a look at how this host is implemented:

 
ClassProgram{
Static voidMain (String[] ARGs)
{
Using(ServicehostHost =NewServicehost(Typeof(Service)))
{
Host. open ();

Console. Writeline ("The service is ready .");
Console. Readkey (True);

Host. Close ();
}
}
}
 
 

This is the most common implementation of the host.

We found that there is no SVC file in self-managed mode. As you can see, SVC is only prepared for IIS hosting. If one day you see a WCF Service without SVC, don't be surprised. It's just a self-managed service.

 

In addition, because the client and service are put together, you only need to configure the service endpoint. That is to say, there is only one configuration file.

However, in self-hosting, It is messy to write the contract (contract) and the client together-look at the people's IIS hosting, Ding is a worm, and the service and client are completely separated. Therefore, vs2008 provides us with the WCF Service Library Project template to solve this problem:

So we created such a project and found that the project only contains the contract and configuration file, as shown in:

Next we will be flexible. We can add a console ConsoleProgramConsoleapplication1, and then add a reference to wcfservicelibrary2 (note that it is a project reference, not a service reference). refer to the following example:

C: \ Users \ baoj \ Documents ents \ Visual Studio 2008 \ projects \ wcfservicelibrary2c: \ Users \ baoj \ Documents ents \ Visual Studio 2008 \ projects \ wcfservicelibrary2

Note that we need to transfer the app. config in wcfservicelibrary2 to the leleapplication1 project. You don't need to say the reason ~~

Remember, transfer means cut, not copy. Make sure that the configuration file does not exist in wcfservicelibrary2. Otherwise, an error is reported, indicating that the address is occupied.

Original post address: http://blog.csdn.net/JspAndAsp/archive/2009/10/23/4721531.aspx

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.