常常需要与宿主实例进行交互。这对于使用自托管的方式是不可或缺的。当使用IIS或WAS时,不能直接访问宿主。为了克服这个障碍,WCF提供了一个宿主工厂。在.svc文件中使用Factory标签,使用此工厂,而不使用默认工厂:

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

当不显示使用.svc文件时,也可以在配置文件中指定宿主工厂:

“<serviceActivations>
<add relativeAddress = "MyService.svc"
service = "MyService"
factory = "MyServiceFactory"
/>
</serviceActivations>” 摘录来自: Juval Löwy and Michael Montgomery. “Programming WCF Services”。 iBooks.

自定义宿主工厂类必须继承自ServiceHostFactory类并重写虚方法CreateServiceHost():

“public class ServiceHostFactory : ...
{
protected virtual ServiceHost CreateServiceHost(Type serviceType,
Uri[] baseAddresses);
//More members
}” 摘录来自: Juval Löwy and Michael Montgomery. “Programming WCF Services”。 iBooks.

例如:

“class MyServiceFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType,
Uri[] baseAddresses)
{
ServiceHost host = new ServiceHost(serviceType,baseAddresses); //Custom steps here return host;
}
}” 摘录来自: Juval Löwy and Michael Montgomery. “Programming WCF Services”。 iBooks.

CreateServiceHost()方法其实就相当于IIS或WAS托管服务的Main()方法,你可以以这样的目的来使用它。

尽管对于从 CreateServiceHost 返回的 ServiceHost 可以执行什么操作没有技术限制,但建议您尽可能使工厂实现简单化。如果有大量的自定义逻辑,最好将这些逻辑放入宿主内而不是工厂内,以便可以重用它们。

完整示例:CustomServiceHost.zip

参考:

Juval Löwy and Michael Montgomery. “Programming WCF Services”

使用 ServiceHostFactory 扩展宿主(https://msdn.microsoft.com/zh-cn/library/aa702697.aspx)

Custom Hosting in IIS/WAS的更多相关文章

  1. ASP.NET Core In Process Hosting on IIS with ASP.NET Core 2.2(转载)

    ASP.NET Core 2.2 has been out for a while now and with it come some significant improvements to the ...

  2. Using Custom Domains With IIS Express In Asp.Net Core

    IIS Express是一个Mini版的IIS,能够支持所有的Web开发任务,但是这种设计有一些缺陷,例如只能通过localhost:<port>的方式来访问我们的应用程序,看起来就有点不 ...

  3. Getting Started with OWIN and Katana(Console 代替iis 制作 web服务的简单方案)

    Open Web Interface for .NET (OWIN) defines an abstraction between .NET web servers and web applicati ...

  4. [转]ASP.NET Core 1 Deploy to IIS

    本文转自: http://webmodelling.com/webbits/aspnet/aspnet-deploy-iis.aspx 15 Sep 2016. This tutorial will ...

  5. ASP.NET Core 2.2 和之前版本区别: 可以在IIS上进行ASP.NET核心进程托管 (翻译)

    原文链接: https://weblog.west-wind.com/posts/2019/Mar/16/ASPNET-Core-Hosting-on-IIS-with-ASPNET-Core-22 ...

  6. 000.Introduction to ASP.NET Core--【Asp.net core 介绍】

    Introduction to ASP.NET Core Asp.net core 介绍 270 of 282 people found this helpful By Daniel Roth, Ri ...

  7. .NET Best Practices

    Before starting with best practices tobe followed, it is good to have clear understanding of how mem ...

  8. Linux上运行NET

    今天尝试了下Ubuntu上运行NET程序,按照 https://github.com/aspnet/Home 的指引,一步一步来: 1.安装DNVM(原名KVM) Linux控制台下输入 curl - ...

  9. WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】

    http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...

随机推荐

  1. 给html里面的class添加一个判断语句,判断当前class是否显示(vue)

    当我们想判断这个class是否出现时,其实有很多方法, 我这个是做了一个选项卡,当点击的时候navTitle的值和循环的item的值相同时class就等于borderbottom, 这样我们点击的图层 ...

  2. 使用jQuery和CSS自定义HTML5 Video 控件 简单适用

    Html5 Video是现在html5最流行的功能之一,得到了大多数最新版本的浏览器支持.包括IE9,也是如此.不同的浏览器提供了不同的原生态浏览器视频空间.我们制作自定义视频控件为了在所有的浏览器中 ...

  3. JDBC连接MySQL数据库(一)——数据库的基本连接

    JDBC的概念在使用之前我们先了解一下JDBC的概念, JDBC的全称是数据库连接(Java Database Connectivity),它是一套用于执行SQL语句时的API,应用程序可以通过这套A ...

  4. 关于TCP中对于ACK报文是否需要确认的理解

    首先,TCP是一个面向字节流的协议,它不会对自己的内容做出任何的解释,也不需要做出解释,具体的解释由上层的协议来处理. 其次,TCP是一个面向字节流的协议,它会对它发送的每一个字节负责,确保每一个字节 ...

  5. immutable-js基础

    Immutable.js(和原生方法不同): 用于深层次的数组和对象的比较   数据结构:Map Set Seq List Rang(和原生不同)   首先:先忘记es5 es6的数组对象方法   官 ...

  6. 慎用PHP的unset、array_unique方法

    背景 在日常工作中,可能会经常遇到一些PHP的代码场景,需要我们去除数组中的某个项,通常会直接调用unset方法,但是如果用得不妥,会给自己挖坑 1.实操 以下使用具体例子进行证明假设有数组如下值: ...

  7. Loaded APR based Apache Tomcat Native library 1.1.24 using APR version 1.4.6.

    Loaded APR based Apache Tomcat Native library 1.1.24 using APR version 1.4.6. 我复制的几个地方: MySql C:\WIN ...

  8. 设置utf8编码问题

    注意:乱码和request的具体实现类有关,现在已经查到的是RequestDispatcher.forward调用前使用的是org.apache.catalina.connector.RequestF ...

  9. iOS 相似QQ空间表视图下拉头部视图放大效果实现

    UITableView 是 UIScrollView 的子类. 所以 UIScrollView 的代理方法.在UITableView 上相同可以得到适用. 既然如此那么我们就行知道.在表格下拉的过程中 ...

  10. LeetCode题解 || Longest Substring Without Repeating Characters (O(n)算法)问题

    problem: Given a string, find the length of the longest substring without repeating characters. For ...