惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V2EX - 技术
V2EX - 技术
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
Webroot Blog
Webroot Blog
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
H
Heimdal Security Blog
H
Help Net Security
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
F
Full Disclosure
小众软件
小众软件
S
Securelist
罗磊的独立博客
NISL@THU
NISL@THU
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cisco Blogs
云风的 BLOG
云风的 BLOG
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
S
Schneier on Security
D
DataBreaches.Net
M
MIT News - Artificial intelligence
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
T
Tenable Blog
The Register - Security
The Register - Security
C
Check Point Blog
AWS News Blog
AWS News Blog
Cloudbric
Cloudbric
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
博客园 - 叶小钗
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 司徒正美

博客园 - 蝈蝈

LAMPR Ver 1.0 发布 - 轻松搞定LAMP环境 在Windows Server下集成Apache、Tomcat和IIS Windows Workflow 学习笔记二 序语言流行度最新排行榜,C和C++正在衰落 Windows Workflow学习笔记 EAI,ESB与SOA How to Building ASP.NET AJAX Controls 使用页面Gzip压缩提速 Microsoft AJAX Library 简介 Configuration Section Designer示例 开源的内容管理系统 Windows Live Writer截屏插件 试用Windows Live Writer写博客 wcf step by step:服务的状态 wcf step by step:消息交换模式 wcf step by step:如何保护你的wcf服务 wcf step by step之异常处理 wcf step by step:host服务与多次Endpoint wcf step by step之HelloWorld
wcf step by step:改进HelloWorld程序
蝈蝈 · 2008-02-29 · via 博客园 - 蝈蝈

在前面我们的blog中,我们的示例在客户端都会包含一个服务器端服务的引用的代理类,这个类是通过vs自动生成的,也可以手工执行svcutil.exe工具生成。我说过,这样会给我们的企业开发带来一些麻烦,服务端服务的接口变化需要手工update那些service reference才可以。还有一个问题是我们的客户端会依赖我们的业务逻辑层。这样客户端在布署时需要把包含逻辑的程序集(dll)。其实对于分布式程序来说,所以的业务逻辑是在服务端完成的,所以包含业务逻辑的dll其实没有必要布署在客户端,客户端只要包含相应的数据和服务契约即可。
这个示例让我们来解决这两个问题,首先把数据契约和服务契约与服务的实现分离到不同的dll中,把数据和服务契约分离到不同的dll中是因为我们的数据实体类需要在各个层次中充当数据交换的载体。而服务契约仅在客户端与服务端交互时才用到,所以把它们分离出来,从组件间的依赖关系中我们也可以看到数据契约组件被很多组件引用,而服务契约则在很多地方不需要。

我们的solution看起来比较复杂了,实际的企业开发中不会比这个简单,我们的demo尽量真实。解决客户端布署的问题就是让Shore.cnlbos.com.WCFClient只引用Shore.cnblogs.com.WCFData,Shore.cnblogs.com.WCFInterface而不再依赖于Shore.cnblogs.com.WCFService了。客户端不再通过svcutil工具生成代理类了,现在我们需要手工来实现一个代理类。先看代码吧

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using Shore.cnblogs.com.WCFInterface;
using Shore.cnblogs.com.WCFData;

namespace Shore.cnblogs.com.WCFClient
{
    public class EmployeeServiceProxy : ClientBase<IEmployeeService>,IEmployeeService
    {
        public EmployeeServiceProxy() : base()
        {
        }

        public EmployeeServiceProxy(string endpointConfigName)
            : base(endpointConfigName)
        {
        }

        public EmployeeServiceProxy(Binding binding, EndpointAddress address)
            : base(binding, address)
        {
        }


        #region IEmployeeService Members

        public void AddEmployee(Employee em)
        {
            Channel.AddEmployee(em);
        }

        public string GetEmpNameByID(int id)
        {
            return Channel.GetEmpNameByID(id);
        }

        #endregion
    }
}

很简单,只需要实现从ClientBase<T>的类继承下来,然后实现服务契约的接口就行,它的实现只是简单的调用Channel.XXX就是,所以我们把它叫proxy。

下载Demo