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

推荐订阅源

Jina AI
Jina AI
T
Threat Research - Cisco Blogs
量子位
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
F
Fortinet All Blogs
爱范儿
爱范儿
D
Docker
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
A
About on SuperTechFans
P
Proofpoint News Feed
博客园 - 司徒正美
Recent Announcements
Recent Announcements
I
InfoQ
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
有赞技术团队
有赞技术团队
Webroot Blog
Webroot Blog
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
SecWiki News
SecWiki News
Attack and Defense Labs
Attack and Defense Labs
Hacker News: Ask HN
Hacker News: Ask HN
AI
AI
博客园_首页
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Recorded Future
Recorded Future
T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
T
Tenable Blog
宝玉的分享
宝玉的分享
Google Online Security Blog
Google Online Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Secure Thoughts
C
Check Point Blog
S
Security Affairs
L
LINUX DO - 最新话题
大猫的无限游戏
大猫的无限游戏
Scott Helme
Scott Helme
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
月光博客
月光博客
Y
Y Combinator Blog

博客园 - 蝈蝈

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