Use IIS as the host to publish the WCF Service

Source: Internet
Author: User


Benefits: If IIS is used as the host, a host is not required for the service.ProgramAnd deployment is relatively easy.

First, prepare the WCF program for testing. This example is just for simple sum calculation,CodeAs follows:


Calculatorservice. SVC(Service file ):

<% @ Servicehost Language = "C #" Debug = " True " Service = " Owenzhang. wcfsamples. calculatorservice " %>


Icalculator. CS(Define a service contract ):

[Servicecontract]
Public   Interface Icalculator
{
[Operationcontract]
Int Add ( Int N, Int M );
}


Calculatorservice. CS(Executing the service contract ):

Public   Class Calculatorservice: icalculator
{
Public   Int Add ( Int N, Int M)
{
Return N + M;
}
}

Note:: Assume that the new project type isWebsiteThen,Icalculator. CSAndCalculatorservice. CSThe file is located inApp_codeFolder. SimilarlyCalculatorservice. SVCCodebehind = "~ /App_code/calculatorservice. cs ".


InWeb. configAdd an endpoint to the file:

<? XML version = " 1.0 " Encoding = " UTF-8 "   ?>
< Configuration >
< System. servicemodel >
< Services >
< Service name = " Owenzhang. wcfsamples. calculatorservice " >
< Endpoint address = "" Binding = " Wshttpbinding " Contract = " Owenzhang. wcfsamples. samples. icalculator "   />
</ Service >
</ Services >
</ System. servicemodel >
</ Configuration >


Then, create a new website or virtual directory in IIS. We will create the virtual directory "C: \ Inetpub \ wwwroot \ calculatorservice" under the default website of the system ", copy the compiled files of the program to the calculatorservice directory, and you can call the service through the endpoint.

Note:: If you are using IIS 7.0 (in Windows Vista and Windows Server 2008 environments), check WCF activation (Server Manager-> features->. HTTP activation (HTTP) and non-HTTP activation (Message Queuing, TCP, and named pipes) in Net Framework 3.0 features have been installed. Otherwise, the related services will fail to be loaded. In addition, if the application extension ing for identifying. SVC files is missing in IIS, you need to add them manually.

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.