Wcf-iis Hosting

Source: Internet
Author: User
Tags hosting

Wcf-iis Hosting

Hosting a WCF service in IIS (Internet information Services) is a step-by-step process. IIS Hosting is illustrated below in detail with the desired coding as well as screenshots to understand the process.

Follow these steps to host a WCF service in IIS. The details of IIS hosting are as follows, and contain the required encoding and to understand the process of IIS hosting

Step 1 : Start Visual Studio and click File-New Web site. Select "WCF Service" and location as HTTP. This would host the service in IIS. Click OK.

Step 1: Launch VS2012, file-to-new-site-->WCF service location Select HTTP. This way, the service will be hosted in IIS

PS: Location this piece needs to first add a site locally and start. IIS Manager, you can start-run-Enter IIS, select the corresponding program

The schema diagram for the newly created project is as follows

Step 2 : The code behind the interface is given below. The code for the interface is as follows

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Serialization;usingSystem.ServiceModel;usingSystem.ServiceModel.Web;usingSystem.Text;//Note: Using the rename command on the Refactor menu, you can change the interface name "IService" in code and configuration files at the same time. [ServiceContract] Public Interfaceiservice{[OperationContract]stringGetData (intvalue);    [OperationContract]    Compositetype getdatausingdatacontract (Compositetype composite); //TODO: Add your service actions here}//use the data contract described in the following example to add a composite type to a service operation. [DataContract] Public classcompositetype{BOOLBoolvalue =true; stringStringValue ="Hello"; [DataMember] Public BOOLBoolvalue {Get{returnBoolvalue;} Set{Boolvalue =value;} } [DataMember] Public stringStringValue {Get{returnStringValue;} Set{stringvalue =value;} }}

Step 3 : The code behind the class file is given below. Code that implements the class of the interface

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Serialization;usingSystem.ServiceModel;usingSystem.ServiceModel.Web;usingSystem.Text;//Note: Using the rename command on the Refactor menu, you can change the class name "service" in code, services, and configuration files at the same time.  Public classservice:iservice{ Public stringGetData (intvalue) {        return string. Format ("You entered: {0}", value); }     Publiccompositetype getdatausingdatacontract (Compositetype composite) {if(Composite = =NULL)        {            Throw NewArgumentNullException ("Composite"); }        if(composite. Boolvalue) {composite. StringValue+="Suffix"; }        returnComposite; }}

Step 4 : Service file (. svc) contains the name of the service and the code behind the file name. This file is used to know about the service.

The service file contains the service name and the name of the code file.

<Language= "C #"  Debug= "true"  service= "Service"  codebehind= "~/app_code/service.cs"  %>

Step 5 : Server-side configurations is mentioned in the config file. Here, there are a mention of only one end-point which are configured to ' Wshttpbinding '; We can also has multiple endpoints with different bindings. Since We is going to host in IIS, we have the use of only HTTP binding.

Server-side configuration is mentioned in the configuration file. Only one endpoint is mentioned here, configured as Wshttpbinding. We can also have multiple endpoints with different binding for each endpoint. Because we are only hosting in IIS, we only need to use HTTP bindings

Step 6:

    • You need to mention the service file name, along and the Address mentioned in the config file. The screenshot of IIS is given here.

    • Click Start, run, inetmgr which would open the following window.

First select the content view in the features view and the content view, then select the. svc file, right-click, and then select Browse

Step 7 : Run the application which would produce the following screen.

Wcf-iis Hosting

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.