当前位置:编程学习 > 网站相关 >>

Wcf通讯基础框架方案(二)——集中配置

 从这次开始在几个方面简单阐述一下实现,集中配置是这个框架很大的一个目的,首先在数据库中会有这么一些表:

image

 

其实可以看到这些表的结构,应该是和<system.serviceModel>配置节点中的层次有对应的

1) Service表描述的是服务,主要保存服务行为以及服务的配置。在这里,ServiceConfig是框架内用到的配置,比如各种日志是否要记录等等。服务对应到服务的集群,集群公开一个地址,客户端访问这个地址,也就是一个负载均衡的虚拟IP地址。

2) 一个Service可以有多个ServiceEndpoint,ServiceEndpoint中定义了契约的版本,类型和行为,以及涉及到地址的端口、端点名字等。客户端和服务端部署的服务契约版本号不一定是一致的,在选择端点的时候优先选择匹配的版本。

3) 一个ServiceEndpoint对应一个Binding,一个Binding也可以对应多个ServiceEndpoint。Binding表中记录了绑定类型、优先级、以及协议前缀和绑定的Xml配置。在选择服务端点的时候会优先选择优先级别比较高的绑定。

4) ClientAccess表主要用于限制哪些客户端机器可以访问哪些服务集群。

5) ClientEndpoint表主要用于设置ClientEndpoint的行为Xml(和ServiceEndpoint行为Xml不能保持一致,对于绑定客户端和服务端是公用的)。

上述这些逻辑可以体现在配置服务的两个方法实现中:

    public WcfService GetWcfService(string serviceType, string serviceContractVersion, string machineName)
        {
            using (WcfConfigDataContext data = new WcfConfigDataContext())
            {
                var wcfService = (from service in data.Services
                                  where service.ServiceType == serviceType && (service.ServerMachineName == "*" || service.ServerMachineName == machineName)
                                  select new WcfService
                                  {
                                      ServiceType = serviceType,
                                      ServiceBehaviorXml = service.ServiceBehaviorXml.ToString(),
                                      Endpoints = (from ep in data.ServiceEndpoints
                                                   where ep.ServiceType == serviceType && ep.ServiceContractVersion == serviceContractVersion
                                                   select new WcfServiceEndpoint
                                                   {
                                                       EndpointBehaviorXml = ep.ServiceEndpointBehaviorXml.ToString(),
                                                       EndpointBindingName = ep.ServiceEndpointBindingName,
                                                       EndpointName = ep.ServiceEndpointName,
                                                       EndpointPort = ep.ServiceEndpointPort,
                                                       ServiceContractType = ep.ServiceContractType,
                                                       EndpointBindingType = ep.Binding.BindingType,
                                                       EndpointBindingXml = ep.Binding.BindingXml.ToString(),
                                                       EndpointProtocol = ep.Binding.BindingProtocol
                                                &n

补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,