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

推荐订阅源

V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
The Last Watchdog
The Last Watchdog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Secure Thoughts
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
博客园 - Franky
有赞技术团队
有赞技术团队
Google Online Security Blog
Google Online Security Blog
罗磊的独立博客
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
NISL@THU
NISL@THU
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Commits to openclaw:main
Recent Commits to openclaw:main
K
Kaspersky official blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
W
WeLiveSecurity
SecWiki News
SecWiki News
Google DeepMind News
Google DeepMind News
O
OpenAI News
V
V2EX
AI
AI
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
美团技术团队
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 三生石上(FineUI控件)
G
GRAHAM CLULEY
月光博客
月光博客
T
Threatpost
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
Last Week in AI
Last Week in AI
爱范儿
爱范儿
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cloudbric
Cloudbric
酷 壳 – CoolShell
酷 壳 – CoolShell
The Hacker News
The Hacker News
N
News | PayPal Newsroom
Know Your Adversary
Know Your Adversary

博客园 - 蝈蝈

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