[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中宿主一个服务的主要优点是在发生客户端请求时宿主进程会被自动启动,并且你可以 ...
随机推荐
- Unable to chmod
不能改变权限 Unable to chmod /system/build.prop.: Read-only file system 解决方式: before chmod: Code: mount -o ...
- OC中的野指针,空指针,nil,Nil,NULL,NSNULL小结
周末与一个老朋友吃饭聊天,因为他正在培训班学习iOS开发,就随便聊了几句,发现自己OC基础上的欠缺和一些知识点的混淆.特此整理如下. 1.空指针 没有存储任何内存地址的指针就称为空指针(NULL指针) ...
- 使用SQL Server Management Studio 创建作业备份数据库
在项目中,经常需要备份数据库,如果能做到只需点个按钮(“开始备份数据库”按钮),然后什么都不管,数据库就自动备份好了,或者服务器上的数据库隔一段时间自动备份一次,那该多好啊. Sql server 的 ...
- 【转】javascript Object使用Array的方法
原文: http://www.cnblogs.com/idche/archive/2012/03/17/2403894.html Array.prototype.push push向数组尾部添加一项并 ...
- 【stack】模拟网页浏览 poj 1028
#include<stdio.h> #include<string.h> int main() { ][]; ]; int i,depth; strcpy(s[]," ...
- js、html中的单引号、双引号及其转义使用
js.html中的单引号.双引号及其转义使用在js中对相关字符做判断或取值的时候很多情况下都会用到这些. ------ 在一个网页中的按钮,写onclick事件的处理代码,不小心写成如下:<in ...
- Spotlights
Spotlights time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- 404、500、502等HTTP状态码介绍
基本涵盖了所有问题HTTP 400 – 请求无效HTTP 401.1 – 未授权:登录失败HTTP 401.2 – 未授权:服务器配置问题导致登录失败HTTP 401.3 – ACL 禁止访问资源HT ...
- 解决phpmyadmin 点击表结构时卡顿、一直加载、打不开的问题
本文内容是转自其它站点,亲测可用. 第一步,打开 ./version_check.php文件,找到以下代码: $save = true; $file ='http://www.phpmyadmin.n ...
- The Accumulation of Capital
The Accumulation of Capital ---- by *Adam Smith Capitals are increased by parsimony, and diminished ...