惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
大猫的无限游戏
大猫的无限游戏
NISL@THU
NISL@THU
Scott Helme
Scott Helme
G
Google Developers Blog
T
Threat Research - Cisco Blogs
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Exploit Database - CXSecurity.com
G
GRAHAM CLULEY
The Cloudflare Blog
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
N
Netflix TechBlog - Medium
Hacker News: Ask HN
Hacker News: Ask HN
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Cisco Blogs
O
OpenAI News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Forbes - Security
Forbes - Security
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
S
Security Affairs
B
Blog RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Privacy & Cybersecurity Law Blog
Martin Fowler
Martin Fowler
Know Your Adversary
Know Your Adversary
F
Full Disclosure
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google DeepMind News
Google DeepMind News
博客园 - Franky
F
Fortinet All Blogs
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
L
Lohrmann on Cybersecurity
T
Tenable Blog
V
V2EX
W
WeLiveSecurity
Google Online Security Blog
Google Online Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed

博客园 - 蝈蝈

LAMPR Ver 1.0 发布 - 轻松搞定LAMP环境 在Windows Server下集成Apache、Tomcat和IIS Windows Workflow 学习笔记二 序语言流行度最新排行榜,C和C++正在衰落 Windows Workflow学习笔记 EAI,ESB与SOA How to Building ASP.NET AJAX Controls 使用页面Gzip压缩提速 Microsoft AJAX Library 简介 Configuration Section Designer示例 开源的内容管理系统 Windows Live Writer截屏插件 试用Windows Live Writer写博客 wcf step by step:服务的状态 wcf step by step:消息交换模式 wcf step by step:如何保护你的wcf服务 wcf step by step之异常处理 wcf step by step:改进HelloWorld程序 wcf step by step之HelloWorld
wcf step by step:host服务与多次Endpoint
蝈蝈 · 2008-02-28 · via 博客园 - 蝈蝈

    WCF的服务需要一个宿主程序来承载。我们可以选择用Windows Activation Service(WAS,for vista),IIS,WPF,Windows Form,Console或Windows Service程序来当作wcf的宿主程序。
  在上一篇中我们没有提到宿主程序的概念但也能运行,其实是宿主在IIS上,还记得我们需要在IIS配置虚拟目录么。
现在我们用其它的方式来宿主,并实现一个服务绑定多个Endpoint。
一种方式是wpf程序,通过配置文件绑定Endpoint,另一种方式以编程方式绑定Endpoint的windows service程序。以编程的方式绑定是出于演示目的,实际的应用场景中都会以配置文件的方式提供绑定,因为这样具有更多的灵活性。
需要注意的是我们不需要为service指定behaviorConfiguration属性了。但需要显式指定endpoint的address。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="HelloWorldWCF.EmployeeService">
        <endpoint address="http://localhost:8000/HelloWorldWCFdemo/EmployeeService.svc"
          binding="basicHttpBinding" name="EmployeeServiceHttpEndpoint"
          contract="HelloWorldWCF.IEmployeeService" />
        <endpoint address="net.tcp://localhost:8080/tcpEndpoint" binding="netTcpBinding"
          bindingConfiguration="" name="EmployeeServiceTcpEndpoint" contract="HelloWorldWCF.IEmployeeService" />
      </service>
    </services>
  </system.serviceModel>
</configuration>
客户端仍然是通过svcUtil工具生成的代理文件来完成与服务器的通讯的。因为这种方式比较简单,实际的企业应用中这样做太麻烦,每次服务接口有修改客户端需要update一次service reference才可以使用。后面我们会用一种更友好的方式来实现,服务器端和客户端共享数据和接口。客户端与上次没有太大变化,需要注意的是配置文件和New一个服务的客户端代理对像时我们传入一个endpoint的名给它,因为我们配置了多个endpoint,我们需要告诉它当前用哪一个。
下面是运行的效果图,请注意我们让HelloWorldWCFClient启动了多个实例,并都处于调试状态。通过输入不同而使用不同的协议与同一个服务器端通讯。因为我们的服务绑定了多个endpoint

下载源码:

https://files.cnblogs.com/shore/chapter%202.zip