Reposted in this article: Workshop
During project development, we may select the http or tcp-bound wcf Service in a timely manner. You can use the console to host the service, or use IIS to host the service, because of the processing capability of IIS for requests and exceptions, we can save a lot of development effort and become the first choice for hosting services. Previously, the WCF Service was hosted on the console, today, I explored the process of using tcp-bound wcf to host IIS7 and shared it with my friends who want to port the service to IIS.
Instance
We still use a service as an example. We create a new WCF Application with a simple service Service1.svc by default,
Code [ServiceContract]
Public interface IService1
{
[OperationContract]
String GetData (int value );
}
Public class Service1: IService1
{
Public string GetData (int value)
{
Return string. Format ("You entered: {0}", value );
}
}
The configuration of web. config is very simple. Automatic Generation is not described. Copy the code and start porting
Next, we need to port this common service Host to IIS,
First, you must change the web. config file and set the service configuration to net. tcp binding.
The configuration file is as follows:
Code <System. serviceModel>
<Bindings>
<NetTcpBinding>
<Security mode = "None">
<Transport clientCredentialType = "Windows" protectionLevel = "EncryptAndSign"/>
<Message clientCredentialType = "Windows"/>
</Security>
</Binding>
</NetTcpBinding>
</Bindings>
<Services>
<Service behaviorConfiguration = "MyBehavior" name = "WCFService. Service1">
<Endpoint address = "" binding = "netTcpBinding" contract = "WCFService. IService1" bindingConfiguration = "netTcpBindConfig"> </endpoint>
<Endpoint address = "mex" binding = "mexTcpBinding" contract = "IMetadataExchange"> </endpoint>
</Service>
</Services>
<Behaviors>
<ServiceBehaviors>
<Behavior name = "MyBehavior">
<ServiceMetadata/>
<ServiceDebug includeExceptionDetailInFaults = "true"/>
<DataContractSerializer maxItemsInObjectGraph = "6553600"/>
</Behavior>
</ServiceBehaviors>
</Behaviors>
</System. serviceModel>
Copy code
Second, we need to change the properties of the Project WCF Application to facilitate service access during development, right-click the project properties of the service, and switch to the WEB page.
When creating a virtual directory, VS may prompt you to install some IIS6 components. Then, follow the prompts to enable "Update and install windows".
To bind the tcp binding service host of WCF to IIS, you must first enable this function.
Second, you need to install IIS6's compatibility and management tools.
After these steps are completed, you can browse the service, but you may encounter an error:
The handler "svc-Integrated" has an error module "ManagedPipelineHandl…" in its module list...
In this case, you need to confirm two problems. The first one is the DLL used to process the SVC file request,
The second is to re-register asp. net4.0 to IIS after all IIS7 configurations are completed.
In vs2010, check the service http: // localhost/WCFService/Service1.svc and find that the service is OK.
So we can reference and use this service normally.
After the service is referenced, the calling effect is:
Source code: http://files.cnblogs.com/wengyuli/WCFTcpHostToIIS.rar