WCF - IIS 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.

按照如下步骤可以在IIS中托管wcf服务。IIS托管的细节如下所示,并且包含了所需的编码以及截图来明白iIS托管的流程

Step 1 : Start Visual Studio 2012 and click File -> New -> Web site. Select “WCF Service” and Location as http. This will host the service in IIS. Click OK.

步骤1:启动VS2012,文件-->新建-->网站-->WCF服务  位置选择Http。这种方式将会把服务托管在IIS中

ps:位置这一块需要首先在本地添加一个网站,并且启动。  IIS管理器,可以在开始--运行--输入iis,选择对应的程序

新建后的项目的架构图如下所示

Step 2 : The code behind the interface is given below.   接口的代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService”。
[ServiceContract]
public interface IService
{

    [OperationContract]
    string GetData(int value);

    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);

    // TODO: 在此添加您的服务操作
}

// 使用下面示例中说明的数据约定将复合类型添加到服务操作。
[DataContract]
public class CompositeType
{
    bool boolValue = true;
    string stringValue = "Hello ";

    [DataMember]
    public bool BoolValue
    {
        get { return boolValue; }
        set { boolValue = value; }
    }

    [DataMember]
    public string StringValue
    {
        get { return stringValue; }
        set { stringValue = value; }
    }
}

Step 3 : The code behind the class file is given below.  实现接口的类的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、服务和配置文件中的类名“Service”。
public class Service : IService
{
    public string GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }

    public CompositeType GetDataUsingDataContract(CompositeType composite)
    {
        if (composite == null)
        {
            throw new ArgumentNullException("composite");
        }
        if (composite.BoolValue)
        {
            composite.StringValue += "Suffix";
        }
        return composite;
    }
}

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.

服务文件包含服务名称以及代码文件的名称,

<%@ ServiceHost Language="C#" Debug="true" Service="Service" CodeBehind="~/App_Code/Service.cs" %>

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

服务端配置在配置文件中有提到。这里仅仅提到了一个终结点,配置为wsHttpBinding。我们也可以有多个终结点,每个终结点有不同的binding。因为我们只是在IIS中托管,所以我们只需使用http绑定

Step 6:

  • You need to mention the service file name, along with the Address mentioned in the config file. The screenshot of IIS is given here.
  • Click Start -> run -> inetmgr which will open the following window.

首先在功能视图和内容视图中选择内容视图,然后选中.svc文件,右键,然后选择浏览

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

时间: 2024-08-30 07:16:14

WCF - IIS Hosting的相关文章

wcf iis host 打开exe失败 不能显示界面

最近谷歌没法用了,我的freegate经常性的崩溃 无奈之下,用了必应,貌似也不错 http://stackoverflow.com/questions/8414514/iis7-does-not-start-my-exe-file-by-process-start Edit: After a long journey, me and Nasenbaer have found the following. The possible reasons for IIS to fail run an E

zz部署wcf iis

http://blog.csdn.net/jiankunking/article/details/44118911 一. 环境vs2010,WCF应用程序,server 2008 第一步:WCF项目右键点击项目,选择生成部署包,如下图: 第二步:WCF项目上右键,选择:在windows资源管理器中打开文件夹,如下图: 第三步:第二步:在你项目所在的文件目录下找到Package文件夹,这就是我们的部署包所在的地方.在这个package文件夹下面有一个packageTmp. 第四步:在IIS上新建虚

WCF IIS 部署错误处理

做Web接口,原来一直用Web Service的,但是.Net 3.5后,Web Service变成了WCF.代码的编写上,把WebMethod特性改成了OperationContract,然后把方法分拆到契约接口和实现方法.然后在部署上,不再依赖于IIS,但如果使用IIS,部署反倒麻烦了. 将WCF应用程序代码拷贝到IIS目录下,然后打开IIS管理器,将其转换为Application.访问时出现了错误.protocolMapping配置节有问题. 原因在于,WCF是.Net3.5?的东西,我创

WCF IIS 服务器 500 错误 检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(转)

我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误: HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设置. 为什么会出现以上错误? 在IIS7的应用程序池有两种模式,一种是"集成模式",一种是"经典模式". 经典模式 则是我们以前习惯的IIS 6 的方式. 如果使用集成模式,那么对自定义的httpModules 和 httpHandlers 就要修改配置文件,需

WCF IIS上部署服务

一.选择应用程序池:.Net Framework 4.0集成模式 二.IIS Access is denied:程序所在文件夹给予Everyone权限 三.HTTP 错误 500.21 - Internal Server Error:以管理员身份注册IIS(32位或64位), %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i 32位机器: C:\Windows\Microsoft.NET\Framework\v4.0

(WCF) WCF Service Hosting.

3 Options. 1. Host inside of an application. 2. Host into Windows service. 3. Host into IIS 参考: http://www.codeproject.com/Articles/38160/WCF-Service-Library-with-Windows-Service-Hosting http://www.tuicool.com/articles/URBfm2

WCF IIS部署

创建WCFHost应用程序 Iservice.cs 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.ServiceModel; 6 using System.ServiceModel.Description; 7 using System.Drawing; 8 namespace WCFHost 9 { 10 11 12 13

WCF - Hosting WCF Service

After creating a WCF service, the next step is to host it so that the client applications can consume it. This is known as WCF service hosting. A WCF service can be hosted by using any of the four ways given below: 在创建wcf服务后,下一个步骤就是托管该服务,确保客户端应用可以使用它

Hosting socket.io WebSocket apps in IIS using iisnode

In this post I explain how to configure a socket.io node.js application to use of WebSockets when hosting it in IIS 8 using iisnode. This complements a recent post in which I showed how to host node.js WebSocket applications in IIS on Windows using i