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,选择对应的程序

5){_OL1VVG2BW.png)

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

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的更多相关文章
- 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 ...
- WCF - WAS Hosting
WCF - WAS Hosting To understand the concept of WAS hosting, we need to comprehend how a system is co ...
- 【记录】WCF IIS 404
WCF IIS 发布报"404错误": 修改 Web.config 如下: <system.webServer> <handlers> <remove ...
- wcf iis host 打开exe失败 不能显示界面
最近谷歌没法用了,我的freegate经常性的崩溃 无奈之下,用了必应,貌似也不错 http://stackoverflow.com/questions/8414514/iis7-does-not-s ...
- WCF - Self Hosting
WCF - Self Hosting Here, the WCF service is hosted in a console application. Given below is the proc ...
- [WCF]IIS部署到新系统
最近为以前的一个企业部署软件的时候,接触到WCF,通过博客园大佬的系列文章和一些书籍,基本了解了一些.简单说也算是SOA一种方式,提供某种服务,可以理解为一个类库,供其他项目使用,可以做到业务分离.但 ...
- WCF IIS 部署错误处理
做Web接口,原来一直用Web Service的,但是.Net 3.5后,Web Service变成了WCF.代码的编写上,把WebMethod特性改成了OperationContract,然后把方法 ...
- (WCF) WCF Service Hosting.
3 Options. 1. Host inside of an application. 2. Host into Windows service. 3. Host into IIS 参考: http ...
- WCF IIS上部署服务
一.选择应用程序池:.Net Framework 4.0集成模式 二.IIS Access is denied:程序所在文件夹给予Everyone权限 三.HTTP 错误 500.21 - Inter ...
随机推荐
- C#上传图片和生成缩略图以及图片预览
因工作需要,上传图片要增加MIME类型验证和生成较小尺寸的图片用于浏览.根据网上代码加以修改做出如下效果图: 前台代码如下: <html xmlns="http://www.w3.or ...
- 2017 google Round C APAC Test 题解
题解参考网上的答案,以及我自己的想法. 主要参考网站:http://codeforces.com/blog/entry/47181,http://codeforces.com/blog/entry/4 ...
- [翻译]log4net教程
原文:log4net Tutorial 一.基础: log4net分为三部分:配置.设置和调用.配置通常是在app.webconfig或web.config文件中:为了增加灵活性,我们也可以使用单独的 ...
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
- 【原创】开机出现grub rescue,修复办法
出现这种问题 一般在于进行了磁盘分区(GHOST备份时也会造成)导致grub引导文件找不到.我们只要让它找到引导文件就好了. 此时屏幕上提示grub resume> 我们先输入set看下现在g ...
- MySQL复制(三) --- 高可用性和复制
实现高可用性的原则很简单: 冗余(Redundancy):如果一个组件出现故障,必须有一个备用组件.这个备用组件可以是standing by的,也可以是当前系统部署中的一部分. 应急计划(Contig ...
- python参考手册 Read
P28 复制 a = [1,2,3,[1,2]] b = a b is a # True c = list[a] # shallow copy c is a # False c[3][0] = 100 ...
- Python数据库连接池实例——PooledDB
不用连接池的MySQL连接方法 import MySQLdbconn= MySQLdb.connect(host='localhost',user='root',passwd='pwd',db='my ...
- spring IOC源码分析(3)
1.IOC容器的依赖注入 Spring中,依赖注入是在用户第一次向IOC容器索要Bean时触发的(通过getBean方法). 在BeanFactory中我们看到getBean(String…)函数,它 ...
- bootstrap form
http://getbootstrap.com/examples/starter-template/ <form class="form-horizontal" role=& ...