[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中宿主一个服务的主要优点是在发生客户端请求时宿主进程会被自动启动,并且你可以 ...
随机推荐
- Openlayer 3 图层列表控件(自定义)
<body><div id="map"></div><div id="layerControl" class=&quo ...
- 转换流--InputStreamReader ,OutputStreamWriter
BufferedReader 字符流,只能装饰字符流,不能装饰字节流.有个重要且好用的方法是readLine()整行读取字符. 但是InputStream是字节流,没有resdLine方法,那么字节流 ...
- java的两种异常runtimeException和checkedException
java异常处理机制主要依赖于try,catch,finally,throw,throws五个关键字. try 关键字后紧跟一个花括号括起来的代码块,简称try块.同理:下面的也被称为相应的块. ...
- C: define many functions using predefine..
/* Defines COUNTER. There must be exactly one such definition at file scope * within a program. */ # ...
- DHCPv6
SLAAC(RFC4862)(StatelessAddressAutoconfiguration),无状态自动配置 IT网,http://www.it.net.cn DHCPv6包含以下两种形式: n ...
- ZOJ Problem - 2588 Burning Bridges tarjan算法求割边
题意:求无向图的割边. 思路:tarjan算法求割边,访问到一个点,如果这个点的low值比它的dfn值大,它就是割边,直接ans++(之所以可以直接ans++,是因为他与割点不同,每条边只访问了一遍) ...
- Django - 用户注册
使用Django工程自动创建的auth_user表来存储用户信息 在app目录下创建forms.py mysite/music/forms.py from django.contrib.auth.mo ...
- Win7下安装配置Java
1 安装JDK java.sun.com 下载 Java SE Development Kit 2 配置环境变量 变量名:JAVA_HOME 变量值:C:\Program Files (x86)\J ...
- Dev之ChartControl控件(一)
ChartControl控件主要包括Chart Title,Legend,Annotations,Diagram,Series五部分:如图: 1. 用RangeControl控件控制ChartCon ...
- spring,hibernate配置事务
1. 新建java project 2. 引入jar 3. src下新建package:com.web.model, com.web.dao, com.web.service, bean.xml 4. ...