[Programming WCF Services]Chapter 1. WCF Essentials - EndPoint
1.配置文件方式设置EndPoint(ABC)
1.1.基本配置
<system.serviceModel>
<services>
<service name="MyNamespace.MyService">
<endpoint address="http://localhost:8000/MyService" binding="wsHttpBinding" contract="MyNamespace.IMyContract"/>
</service>
</services>
</system.serviceModel>
1.2.为一个Service配置多个结点
<service name="MyService">
<endpoint address="http://localhost:8000/MyService" binding="wsHttpBinding" contract="IMyContract"/>
<endpoint address="net.tcp://localhost:8001/MyService" binding="netTcpBinding" contract="IMyContract"/>
<endpoint address="net.tcp://localhost:8002/MyService" binding="netTcpBinding" contract="IMyOtherContract"/>
</service>
1.3.基地址
<system.serviceModel>
<services>
<service name="MyNamespace.MyService">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8001/"/>
<add baseAddress="http://localhost:8002/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
1.4.使用绑定
<system.serviceModel>
<services>
<service name="MyService">
<endpoint address="net.tcp://localhost:8000/MyService" bindingConfiguration="TransactionalTCP" binding="netTcpBinding" contract="IMyContract"/>
<endpoint address="net.tcp://localhost:8001/MyService" bindingConfiguration="TransactionalTCP" binding="netTcpBinding" contract="IMyOtherContract"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="TransactionalTCP" transactionFlow="true"/>
</netTcpBinding>
</bindings>
</system.serviceModel>
默认绑定
应用到所有没有直接指定bindingConfiguration的EndPoint。一种绑定类型BasicHttpBinding/netTcpBinding/wsHttpBinding/...只能有一个默认配置
<netTcpBinding>
<binding transactionFlow="true"/> <!--没有name属性-->
</netTcpBinding>
2.代码方式设置EndPoint
2.1.基本方式
ServiceHost host = new ServiceHost(typeof(MyService));
Binding wsBinding = new WSHttpBinding();
Binding tcpBinding = new NetTcpBinding();
host.AddServiceEndpoint(typeof(IMyContract),wsBinding,
"http://localhost:8000/MyService");
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,
"net.tcp://localhost:8001/MyService");
host.AddServiceEndpoint(typeof(IMyOtherContract),tcpBinding,
"net.tcp://localhost:8002/MyService");
host.Open();
2.2.使用基地址
Uri tcpBaseAddress = new Uri("net.tcp://localhost:8000/");
ServiceHost host = new ServiceHost(typeof(MyService),tcpBaseAddress);
Binding tcpBinding = new NetTcpBinding();
//Use base address as address
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,"");
//Add relative address
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,"MyService");
//Ignore base address
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,
"net.tcp://localhost:8001/MyService");
host.Open();
2.3.使用绑定
ServiceHost host = new ServiceHost(typeof(MyService)); //没有基地址
NetTcpBinding tcpBinding = new NetTcpBinding();
tcpBinding.TransactionFlow = true; //设置绑定属性
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,
"net.tcp://localhost:8000/MyService");
host.Open();
使用下列构造函数,可以使用配置文件中的指定绑定配置来初始化绑定,或是使用空串来使用默认的绑定配置
public class NetTcpBinding : Binding,...
{
public NetTcpBinding(string configurationName);
//More members
}
3.默认EndPoint
如果没有在配置文件和代码中提供终结点,WCF会生成自动生成默认终结点
例如代码:
[ServiceContract]
interface IMyContract
{...}
[ServiceContract]
interface IMyOtherContract
{...}
class MyService : IMyContract,IMyOtherContract
{...}
for this hosting code:
Uri httpBaseAddress = new Uri("http://localhost:8000/");
Uri tcpBaseAddress = new Uri("net.tcp://localhost:9000/");
Uri ipcBaseAddress = new Uri("net.pipe://localhost/");
ServiceHost host = new ServiceHost(typeof(MyService),
httpBaseAddress,tcpBaseAddress,ipcBaseAddress);
//在host open之前没有添加任何终结点
host.Open();
WCF自动生成的终结点如下:
<service name = "MyService">
<endpoint name = "BasicHttpBinding_IMyContract"
address = "http://localhost:8000/"
binding = "basicHttpBinding"
contract = "IMyContract"
/>
<endpoint name = "NetTcpBinding_IMyContract"
address = "net.tcp://localhost:9000"
binding = "netTcpBinding"
contract = "IMyContract"
/>
<endpoint name = "NetNamedPipeBinding_IMyContract"
address = "net.pipe://localhost/"
binding = "netNamedPipeBinding"
contract = "IMyContract"
/>
<endpoint name = "BasicHttpBinding_IMyOtherContract"
address = "http://localhost:8000/"
binding = "basicHttpBinding"
contract = "IMyOtherContract"
/>
<endpoint name = "NetTcpBinding_IMyOtherContract"
address = "net.tcp://localhost:9000"
binding = "netTcpBinding"
contract = "IMyOtherContract"
/>
<endpoint name = "NetNamedPipeBinding_IMyOtherContract"
address = "net.pipe://localhost/"
binding = "netNamedPipeBinding"
contract = "IMyOtherContract"
/>
</service>
也可以通过AddDefaultEndpoints来添加默认结点点。有了这个方法,在已有非终结点的情况下也中添加默认终结点。
public class ServiceHost : ...
{
public void AddDefaultEndpoints();
//More members
}
3.1Protocol mapping
在没有提供终结点的情况下,WCF根据基地址的scheme来推断所需要的绑定。这个就叫Protocol mapping。可以通过配置文件来改变Protocol mapping的行为:
<system.serviceModel>
<protocolMapping>
<add
scheme = "http"
binding = "wsHttpBinding"
/>
</protocolMapping>
</system.serviceModel>
还可以为绑定指定配置:
<protocolMapping>
<add
scheme = "http"
binding = "wsHttpBinding"
bindingConfiguration = "..."
/>
</protocolMapping>
[Programming WCF Services]Chapter 1. WCF Essentials - EndPoint的更多相关文章
- [Programming WCF Services]Chapter 1. WCF Essentials - Metadata Exchange
1.HTTP-GET WCF 方式 通过Http的方式提供metadata 1.1.配置文件方式 <system.serviceModel> <services> <se ...
- How To Easily Call WCF Services Properly z
Please note: this article has been superceded by the documentation for the ChannelAdam WCF Library. ...
- Learing WCF Chapter1 WCF Services
WCF ServicesWCF services are the new distributed boundary in an enterprise application—with an empha ...
- WCF4.0 –- RESTful WCF Services (1) (入门)
WCF 很好的支持了 REST 的开发, 而 RESTful 的服务通常是架构层面上的考虑. 因为它天生就具有很好的跨平台跨语言的集成能力,几乎所有的语言和网络平台都支持 HTTP 请求,无需去实现复 ...
- IIS8.0 部署WCF Services
今天在Win 8的IIS上部署WCF Services,访问SVC文件时出现找不到处理程序的错误,以前遇到这个问题时都是尝试通过注册asp.net的方式处理一下,但是在Win8下这招不灵了,出现如下提 ...
- WCF4.0 –- RESTful WCF Services
转自:http://blog.csdn.net/fangxinggood/article/details/6235662 WCF 很好的支持了 REST 的开发, 而 RESTful 的服务通常是架构 ...
- WCF入门教程:WCF基础知识问与答(转)
学习WCF已有近两年的时间,其间又翻译了Juval的大作<Programming WCF Services>,我仍然觉得WCF还有更多的内容值得探索与挖掘.学得越多,反而越发觉得自己所知太 ...
- WCF学习之旅—WCF寄宿前的准备(八)
一.WCF服务应用程序与WCF服务库 我们在平时开发的过程中常用的项目类型有“WCF 服务应用程序”和“WCF服务库”. WCF服务应用程序,是一个可以执行的程序,它有独立的进程,WCF服务类协定的定 ...
- WCF学习之旅—WCF服务部署到IIS7.5(九)
上接 WCF学习之旅—WCF寄宿前的准备(八) 四.WCF服务部署到IIS7.5 我们把WCF寄宿在IIS之上,在IIS中宿主一个服务的主要优点是在发生客户端请求时宿主进程会被自动启动,并且你可以 ...
随机推荐
- CentOS6.6 部署Apache+Svn
svn代码 目前大多数公司 管理代码都是用这个 这个比较方便简单,git用的人数也比较多,我们下面来部署一下这个程序 svn+apache集成 系统环境 # cat /etc/redhat-relea ...
- 5.1 timestamp数据类型默认值
5.1 不支持同一张表中有多个tmiestamp类型字段的默认值为current_time, 5.6版本无此问题
- typeof判断类型(数组类型得用instanceof)
var a= 1; console.log(typeof a); var b= '1'; console.log(typeof b); var c; console.log(typeof c); va ...
- 格式化格林威治时间(Wed Aug 01 00:00:00 CST 2012)
1.如果格林威治时间时间是date类型.(这种格式最简单) SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd") ...
- Spring Boot 系列教程17-Cache-缓存
缓存 缓存就是数据交换的缓冲区(称作Cache),当某一硬件要读取数据时,会首先从缓存中查找需要的数据,如果找到了则直接执行,找不到的话则从内存中找.由于缓存的运行速度比内存快得多,故缓存的作用就是帮 ...
- WordPress 邮箱防抓取
现在网络上有很多爬虫,专门四处搜集网站代码中出现的邮箱,搜集到了之后就批量出售或者发送垃圾邮件.很多人都把邮箱中的 “@” 换成 “#”,但这样对用户不太方便,而且这种方法很多机器人都可以识破,同样被 ...
- 444A/CF
题目链接[http://codeforces.com/problemset/problem/444/A] 题意:给出一个无向图,找出一个联通子图,定义密度#=v(顶点值的和)/e(边值的和). 条件: ...
- Office2003/2010等集成SP的简单方法
Office2003集成SP的简单方法 需要准备的工具:Office 2003 光盘镜像.SP3更新包.Office 2003 序列号.UltraISO,7-zip或winrar,虚拟光驱 步骤一:提 ...
- Linux学习 -- Shell编程 -- 字符处理命令
sort排序命令 sort [选项] 文件名 -f 忽略大小m写 -n 按数值型,默认字符串型 -r 反向 -t 指定分隔符 -k n[,m] 指定字段范围,默认行尾 eg. sort -n -t & ...
- Entity Framework 学习初级篇3-- LINQ TO Entities
LINQ 技术(即 LINQ to Entities)使开发人员能够通过使用 LINQ 表达式和 LINQ 标准查询运算符,直接从开发环境中针对 实体框架对象上下文创建灵活的强类型查询.LINQ to ...