This article from: http://www.cnblogs.com/poissonnotes/archive/2010/08/28/1811141.html
In the previous article, we created a simple WCF Service. During the test, we used the wcfsvchost (WCF Service host) that comes with vs2008 to publish the WCF Service for testing. This built-in wcfsvchost in vs2008 is only applicable to developers for testing and can be used for WCF Service deployment. This articleArticleLet's take a look at how to publish the WCF Service we made in the previous article in the middle of IIS.
Step 1: OpenWCFService Project.
Figure 1
Step 2: CreateWCFService site.Right-click the solution and choose add> New website to open the new website dialog box. In the "Add new website" dialog box, select "WCF Service" and name the website name as "bookservicehost"
Figure 2
The results of the newly created WCF Service site are as follows. Two class files are automatically generated for us in the app_code file: iservice. CS and service. CS. These two files are useless for us. We delete them.
Figure 3
Step 3:WCFAdd a pair to the service stationWCFService Library Project-- ServicesProject reference.
Figure 4
Step 4: ConfigureService. SVCFile.
Double-click the service. SVC file and we can see its declaration instructions as follows:
<% @ Servicehost Language = "C #" DEBUG = "true" service = "service" codebehind = "~ /App_code/service. cs "%>
Because the iservice. CS and service. CS files have been deleted in step 2, modify the instructions here to make the background of the service. SVC FileCodePoint to the class in the WCF Service library project -- services project that we created last time. The modified code is as follows:
<% @ Servicehost Language = "C #" DEBUG = "true" service = "services. bookservice" %>
We specify the service attribute as the bookservice class under the Services namespace and delete the codebehind attribute.
Step 5: configure thisWCFService site andWCFThe class correspondence between service library projects.
Although we added a reference to the services project in step 3, and modified the service in step 4. SVC class, but in this case, our WCF Service site cannot publish the services and endpoints in the WCF Service library. config.
Right-click Web. config and select "Edit WCF configuration"
Figure 5
In the service configuration window that appears, specify the service to the services. bookservice service class in services. dll of the WCF Service library.
Figure 6
Then, set a contract of the external endpoint to the service. ibookservice contract in services. dll of the WCF Service library.
Figure 7
Step 6: Try to add another communication endpoint.
This step is optional. We will add an endpoint for this WCF Service site,A = Basic B = basichttpbinding C = services. ibookservice
Figure 8
Next we will try to use different endpoints to interact with the WCF Service and view the running status.
When we use iis5 or IIS6 to publish a WCF Service, we generally only create an HTTP binding endpoint, rather than an end point that uses TCP binding and MPs queue binding.
Step 7: Test RunWCFService site.
Right-click Service. SVC and select View in browser to run the service in IE.
Figure 9
From this we can see that we can publish our WCF Service in ASP. NET development server.
Step 8:IISDeploy thisWCFService site.
Create a web application in IIS and point it to the directory where our WCF Service site is located. Then run the released WCF Service in IIS.
Figure 10
We can see that the published site no longer contains the port number.
At this point, we have successfully released the WCF Service in IIS.
Next we call the WCF Service that we just released in IIS on the WCF test client.
Ninth point: Enter the following code in the vs2008 command window to run the WCF test client.
X: \... \ wcftestclientHttp: // localhost/testwcfservice/service. SVC
The pop-up test window is as follows:
Figure 11
We can see that there are two endpoints in the published service: the endpoints have different transmission modes, but the methods provided are the same.
We add three objects through the addbooks () method of the first endpoint.
Figure 12
Then, use the getallbooks () method of the second endpoint to obtain information about all objects.
Figure 13
The operation is complete.