Store existing WCF services in IIS

Source: Internet
Author: User

IIS is one of the hosts of the WCF Service. You can select a WCF Service template when creating a web site. However, the site created based on the WCF Service Template integrates the service and host, next let's take a look at how to store an existing WCF Service in IIS.

1. Add a new site to the solution in a simple WCF example article. Select the WCF Service template and set the address to http: // localhost/iishostedservice, for example:

2. After confirmation, the WCF Service template generates a site with services. Because we want to store existing services in the site, we need to delete the services that come with the site, the service file is in the app_code directory, for example:

3. Add a reference to the Service Project, for example:

4. Double-click the service. SVC file in the project, modify the @ servicehost command, and associate it with the service type. The modified code is as follows:

<%@ ServiceHost Language="C#" Debug="true" Service="Service.HelloWorldService"  %>

5. Modify the website's web. config file, find the service node, modify the name attribute of the service node, the binding attribute of the endpoint node, and the contract attribute. The modified code is as follows:

6. Set the site as a startup project and press F5 to run it. If the metadata exchange endpoint is not configured in the web. config file, the following page is displayed after running:

You can configure the metadata exchange endpoint step by step according to the steps on the above page. After the configuration, if the httpgetenabled attribute of the servicemetadata node is set to false, after the operation, as shown in:

When the httpgetenabled attribute is set to true, you can see that the svcutil command is followed by? The URL of the WSDL, for example:

Click this link to view the Service's WSDL document, for example:

7. the IIS host has been written. Now you need to use the svcutil tool to generate a client proxy, open the Command Prompt window of vs2008, and enter the command prompt after running the previous site, such:

8. After execution, a proxy file and a configuration file are generated in the directory c: \ Program Files (x86) \ Microsoft Visual Studio 9.0 \ Vc, copy the two files to the client program and change the configuration file to app. and then add the following code to the client program:

class Program{    static void Main(string[] args)    {        oec2003Client proxy = new oec2003Client();        Console.WriteLine(proxy.SayHello());        proxy.Close();        Console.ReadLine();    }}

9 run the client program and you can see the following results:

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.