Host all records of the WCF Service bound with netTcp to IIS7

Source: Internet
Author: User
Source :【 Http://wengyuli.blog.51cto.com/44136/586564 ]Summary

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.

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>

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:

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.