.Net WCF Service Deployment IIS detailed analysis

  Official resolved: Windows Communication Foundation (WCF) is a series of application framework that supports data communication developed by Microsoft, it can be translated as Windows communications development platform. .Net Remoting integration of the original windows of communication, WebService, Socket mechanism, and fused with HTTP and FTP related technologies.

First, create a WCF service

The first step: create a WCF project

 

 Once created, automatically help us generate these files, two class, an interface, implements an interface, there is a App.config configuration file (WCF specific configuration information in this directory)

 

 IService1.cs

Note: WCF, etc. will be posted to relate to the transmission network on IIS, the object persistence to disk, then we need to be serialized, entity classes, custom attributes, marked with the corresponding label on the class name

. 1  the using the System;
 2  the using the System.Collections.Generic;
 . 3  the using the System.Linq;
 . 4  the using the System.Runtime.Serialization;
 . 5  the using the System.ServiceModel;
 . 6  the using the System.Text;
 . 7  
. 8  namespace WCFDemo
 . 9  {
 10      // NOTE: Use "reconstruction" "rename" command on the menu, you can change the name of the interface code and configuration files "IService1" at the same time. 
. 11      [the ServiceContract]
 12 is      public  interface IService1
 13 is      {
 14          [the OperationContract]
 15          StringThe GetData ( int value);
 16  
. 17          [the OperationContract]
 18 is          CompositeType GetDataUsingDataContract (CompositeType Composite);
 . 19  
20 is          // the TODO: Add your this service operations 
21      }
 22 is  
23 is      // use the data convention described in the following examples to add complex type to a service operation.
24      // You can add XSD file to the project. After generating the project, which can be used directly by the data type defined namespace "WCFDemo.ContractType". 
25      [the DataContract]
 26 is      public  class CompositeType
 27      {
 28          BOOL boolValue = to true ;
 29          String the stringValue ="Hello ";
30 
31         [DataMember]
32         public bool BoolValue
33         {
34             get { return boolValue; }
35             set { boolValue = value; }
36         }
37 
38         [DataMember]
39         public string StringValue
40         {
41             get { return stringValue; }
42             set { stringValue = value; }
43         }
44     }
45 }

Service1.cs

Note: The specific interface

. 1  the using the System;
 2  the using the System.Collections.Generic;
 . 3  the using the System.Linq;
 . 4  the using the System.Runtime.Serialization;
 . 5  the using the System.ServiceModel;
 . 6  the using the System.Text;
 . 7  
. 8  namespace WCFDemo
 . 9  {
 10      // NOTE: Use "reconstruction" "rename" command on the menu, you can change the code and configuration files in the class name "Service1" at the same time. 
. 11      public  class Servicel: IService1
 12 is      {
 13 is          public  String the GetData ( int value)
 14         {
15             return string.Format("You entered: {0}", value);
16         }
17 
18         public CompositeType GetDataUsingDataContract(CompositeType composite)
19         {
20             if (composite == null)
21             {
22                 throw new ArgumentNullException("composite");
23             }
24             if (composite.BoolValue)
25             {
26                 composite.StringValue += "Suffix";
27             }
28             return composite;
29         }
30     }
31 }

App.config

Note: http: // localhost: 8733 / Design_Time_Addresses / WCFDemo / Service1 / The address is posted to our service address on IIS, can be modified, as the case may be,

 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <configuration>
 3 
 4   <appSettings>
 5     <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
 6   </appSettings>
 7   <system.web>
 8     <compilation debug="true" />
 9   </system.web>
10   <!- 11when deploying Service Library project, you must add the contents of the documents to 
   App.config file host. System.Configuration library does not support the configuration file. ->
 12 is    <system.serviceModel>
 13 is      <Services>
 14        <-Service name = " WCFDemo.Service1 " >
 15          <Endpoint address = "" Binding = " the basicHttpBinding " Contract = " WCFDemo.IService1 " >
 16            <Identity>
 . 17              < value = DNS " localhost " />
 18 is            </ Identity>
 . 19          </ Endpoint>
"mex" binding="mexHttpBinding" contract="IMetadataExchange" />
21         <host>
22           <baseAddresses>
23             <add baseAddress="http://localhost:8733/Design_Time_Addresses/WCFDemo/Service1/" />
24           </baseAddresses>
25         </host>
26       </service>
27     </services>
28     <behaviors>
29       <serviceBehaviors>
30         <behavior>
31           <! - To avoid leakage metadata information,
 32            make the following value is set before deployment to false ->
 33 is            <the serviceMetadata httpGetEnabled = " True " httpsGetEnabled = " True " />
 34 is            <! - to receive detailed fault exception information for debugging,
 35            set to the following values to true . Before deployment is provided to false  
36              to avoid leakage abnormality information ->
 37 [            <serviceDebug includeExceptionDetailInFaults = " False " />
 38 is          </ behavior>
 39        </ serviceBehaviors>
     </behaviors>
41   </system.serviceModel>
42 
43 </configuration>

If we want to create a WCF service how to do it?

Just in the project, right click -> Add -> New Item -> WCF service can automatically will help us generate an interface, a class that implements the interface, App.config will add some configuration information

 

 Step two: debugging, testing tool that comes with vs feasibility testing services

On the project: Right -> Debug -> Start a new instance

 

 After following interface will appear

 

 start testing

 

 So far, WCF service has been configured, we will publish the following WCF service on IIS

Two, WCF release

The first step: Publish WCF service

On the project: Right -> Publish

 

 Step Two: Specify location

 

 After the release of documents

 

 

 

 Third, install IIS (installed, ignore the installation steps)

Win10 installation

Control Panel -> Programs -> Enable or disable Windows features

 

 Key:

HTTP error must be checked, otherwise it can not be an error when an error occurs, this is very serious. "

 

 Four, WCF service deployed on IIS

Step 1: Register WCF components

How to see if already registered WCF components, select: Default Web Site == "functional view ==" handler mapping, and then view the file suffix * .svc whether svc-Integrated or svc-ISAPI-4.0_64 / 32bit program deal with:

 

 

Because I have the WCF components registered on the IIS, no, please register

cmd ( administrator runs ): ServiceModelReg.exe -i

 

 Step two: aspnet_regiis.exe registered IIS

  Because of these .net framework4.0 we use the application framework developed, but only the system default registered .NET Framework v2.0.50727, if you do not register the corresponding IIS then we will pop up the following error when accessing interface.

 

 

 

 cmd ( administrator runs ): aspnet_regiis.exe -i

 

 Step 3: Add the application pool for the application

Right -> Add Application Pool

 

 Step Four: Add Site

 

 Select the application pool

In order to ensure the safety of the current site, the need for permissions to verify, click the "connection" and enter a user name, follow these steps, password, and then select OK. ( This step can be ignored )

It represents the current authentication success when you click OK after the completion of the "Test Settings" screen shown below appears.

 

 

 Step Five: Browse the current site

 

 This may be a mistake

 

Access to information, the occurrence of the wrong reasons that are installed higher version of .net framework lead to this error, you can try to solve the following methods: 

solution

 

1  path: C: \ Windows \ System32 \ inetsrv \ config
 2 files: applicationHost.config

 

 The last line of code found in managedHandler plus ", runtimeVersionv2.0" can

1 <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler,runtimeVersionv2.0" />

Then in cmd ( administrator ):

1 The first step: cd C: \ Windows \ Microsoft.NET \ Framework \ V4. .30319 
2 Step Two: aspnet_regiis.exe - iru
 3  
4 up to the second step, basically can be resolved, you can restart .svc

 

 Hey. . . . Win10 systems and more things, the following shows how to begin to solve this problem

Baidu solution is as follows, using the dism tools in order to execute the following command

1 cmd(管理员):
2 
3 dism /online /enable-feature /featurename:IIS-ISAPIFilter
4 
5 dism /online /enable-feature /featurename:IIS-ISAPIExtensions
6 
7 dism /online /enable-feature /featurename:IIS-NetFxExtensibility45
8 
9 dism /online /enable-feature /featurename:IIS-ASPNET45

 

Guess you like

Origin www.cnblogs.com/chenyanbin/p/11583272.html