发文章
发文工具
撰写
网文摘手
文档
视频
思维导图
随笔
相册
原创同步助手
其他工具
图片转文字
文件清理
AI助手
留言交流
WCF SOAP 可靠消息传递提供 SOAP 终结点之间的端对端消息传输可靠性。此消息传递通过克服传输失败和 SOAP 消息级别失败,可在不可靠的网络上实现传输可靠性。具体而言,它为跨 SOAP 或传输中介发送的消息提供了一种基于会话的、单一的和(可选)有序的传送。基于对话的传送可按消息的顺序(可选)将消息分组到一个会话中。
简单的说可靠会话就是保证:
要使用 WCF 可靠会话,使用支持可靠会话的绑定创建一个终结点即可。默认情况下WSDualHttpBinding支持并启用可靠会话的系统定义的绑定。支持可靠会话但默认情况下不启用的系统提供的绑定包括:WSHttpBinding、WSFederationHttpBinding、NetTcpBinding。通过设置绑定的ReliableSessionBindingElement开启可靠会话,在配置文件中设置如下面所示:
<bindings> <wsHttpBinding> <binding name="Binding1"> <reliableSession enabled="true" /> </binding> </wsHttpBinding> </bindings> <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" contract="Microsoft.ServiceModel.Samples.ICalculator" />
在代码中使用:
Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service"); // Create a ServiceHost for the CalculatorService type and provide the base address. using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress)) { // Create a custom binding that contains two binding elements. ReliableSessionBindingElement reliableSession = new ReliableSessionBindingElement(); reliableSession.Ordered = true; HttpTransportBindingElement httpTransport = new HttpTransportBindingElement(); httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous; httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; CustomBinding binding = new CustomBinding(reliableSession, httpTransport); // Add an endpoint using that binding. serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, ""); // Add a MEX endpoint. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri("http://localhost:8001/servicemodelsamples"); serviceHost.Description.Behaviors.Add(smb); // Open the ServiceHostBase to create listeners and start listening for messages. serviceHost.Open(); // The service can now be accessed. Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. serviceHost.Close(); }
ReliableSessionBindingElement各个属性的含义:
来自: 昵称10504424 > 《Wcf》
0条评论
发表
请遵守用户 评论公约
Windows Communication Foundation入门(Part Two) ...
三、WCF的技术要素作为基于SOA(Service Oriented Architecture)的一个框架产品,WCF最重要的就是能够快捷的创建一个服务(Service)。...
WCF Tutorial
} } class Program { static void Main(string[] args) { using (ServiceHost host = new ServiceHost( typeof(StringReverser), new Uri[]{ new Uri("http://localhost:8000"), new Uri(&qu...
那些年我们一起追过的缓存写法(四)
那些年我们一起追过的缓存写法(四)进程缓存。所以把应用进程缓存的数据抽离出来,放在单独进程中,给应用提供一层缓存。Wcf Namedpipe....
WCF from MSDN
WCF
WCF限流(Throttling)体系探秘[上篇]
WCF身份验证之用户名密码认证
WCF身份验证之用户名密码认证。WCF支持多种认证技术,例如Windowns认证、X509证书、Issued Tokens、用户名密码认证等,在跨Windows域分布的系统中,用户名密码认证是比较常用的,要实现用户名密码认证...
[WCF 学习笔记] 3. 消息交换
AddServiceEndpoint(typeof(IContract), new BasicHttpBinding(), "http://localhost:8080/myservice");ChannelFactory<IContract> factory = new ChannelFactory<IContrac...
[老老实实学WCF] 第二篇 配置WCF
[老老实实学WCF] 第二篇 配置WCF.老老实实学WCF.建立基地址:这里用了相对地址''HelloWCFService'',他会和基地址组合在一起(排在后面)成为终结点的地址,这里也可以指定为空字符串...
ServiceHost与宿主寄存
ServiceHost.myServiceHost = new ServiceHost(typeof(Service), baseAddress);ServiceEndpoint AddServiceEndpoint(Type implementedCo...
微信扫码,在手机上查看选中内容