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.

WCF - IIS Hosting的更多相关文章

  1. Learning WCF Chapter1 Hosting a Service in IIS

    How messages reach a service endpoint is a matter of protocols and hosting. IIS can host services ov ...

  2. WCF - WAS Hosting

    WCF - WAS Hosting To understand the concept of WAS hosting, we need to comprehend how a system is co ...

  3. 【记录】WCF IIS 404

    WCF IIS 发布报"404错误": 修改 Web.config 如下: <system.webServer> <handlers> <remove ...

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

    最近谷歌没法用了,我的freegate经常性的崩溃 无奈之下,用了必应,貌似也不错 http://stackoverflow.com/questions/8414514/iis7-does-not-s ...

  5. WCF - Self Hosting

    WCF - Self Hosting Here, the WCF service is hosted in a console application. Given below is the proc ...

  6. [WCF]IIS部署到新系统

    最近为以前的一个企业部署软件的时候,接触到WCF,通过博客园大佬的系列文章和一些书籍,基本了解了一些.简单说也算是SOA一种方式,提供某种服务,可以理解为一个类库,供其他项目使用,可以做到业务分离.但 ...

  7. WCF IIS 部署错误处理

    做Web接口,原来一直用Web Service的,但是.Net 3.5后,Web Service变成了WCF.代码的编写上,把WebMethod特性改成了OperationContract,然后把方法 ...

  8. (WCF) WCF Service Hosting.

    3 Options. 1. Host inside of an application. 2. Host into Windows service. 3. Host into IIS 参考: http ...

  9. WCF IIS上部署服务

    一.选择应用程序池:.Net Framework 4.0集成模式 二.IIS Access is denied:程序所在文件夹给予Everyone权限 三.HTTP 错误 500.21 - Inter ...

随机推荐

  1. java异常处理练习

    异常的练习: 老师用电脑上课. 开始思考上课中出现的问题. 比如问题是    电脑蓝屏.    电脑冒烟. 要对问题进行描述,封装成对象. 可是当冒烟发生后,出现讲课进度无法继续. 出现了讲师的问题: ...

  2. hdu 1316 How many Fibs?(高精度斐波那契数)

    //  大数继续 Problem Description Recall the definition of the Fibonacci numbers:  f1 := 1  f2 := 2  fn : ...

  3. OpenJudge/Poj 2013 Symmetric Order

    1.链接地址: http://bailian.openjudge.cn/practice/2013 http://poj.org/problem?id=2013 2.题目: Symmetric Ord ...

  4. OpenJudge 2979 陪审团的人选 / Poj 1015 Jury Compromise

    1.链接地址: http://bailian.openjudge.cn/practice/2979 http://poj.org/problem?id=1015 2.题目: 总Time Limit: ...

  5. Linux中的时间和时间管理

    Coordinated Universal Time(UTC):协调世界时,又称为世界标准时间,也就是大家所熟知的格林威治标准时间(Greenwich Mean Time,GMT).比如,中国内地的时 ...

  6. 树莓派实现TimeMachine以及samba服务

    最近一段时间感觉用移动硬盘备份Mac电脑很不方便,因为要把移动硬盘拿出来,还要插上电脑备份,看了一下AirPort,但是价钱太贵,况且只能用于Mac备份并不能用于其他的Samba服务等,感觉不太划算, ...

  7. Java知识总结--三大框架

    1 应用服务器有哪些:weblogic,jboss,tomcat 2 Hibernate优于JDBC的地方 1)对jdbc访问数据库进行了封装,简化了数据访问层的重复代码 2)Hibernate 操作 ...

  8. sae-php调试代码,不输出页面

    如果单单使用sae_debug,页面就会输出SAE_DEBUG的信息,所以造成很多问题,例如回复微信服务器的xml,但是不知道就想着调试,结果... 所以怎么解决让调试信息不输出页面呢 看完手册,才知 ...

  9. PHP程序员的技术成长规划(送给迷茫的你)

    按照了解的很多PHP/LNMP程序员的发展轨迹,结合个人经验体会,抽象出很多程序员对未来的迷漫,特别对技术学习的盲目和慌乱,简单梳理了这个每个阶段PHP程序员的技术要求,来帮助很多PHP程序做对照设定 ...

  10. PHP 递归创建目录

    /* 用迭代的方法递归创建目录 其实在PHP5.0.0之后mkdir就已经能递归创建目录了. 这里主要是自己学习迭代,所以拿创建级联目录开刀了. 开发中应该写mkdir('./a/b/c/d/e',0 ...