意图:为了是客户端代理呈现出面向对象的多态的特征
a. 服务端
.契约 实现了契约的继承这个在服务端是一点问题没有,因为oprationcontract可以继承,虽然DataContract不能实现继承,注意IAnimal和IDog都是契约,但是我们通常喜欢用最
具体的那个契约来发布服务,因为他最丰富
using System;
using System.ServiceModel; namespace WCF.Chapter2.InheritanceProxyChaining.Host
{
[ServiceContract]
public interface IAnimal
{
[OperationContract]
string AnimalSay();
} [ServiceContract]
public interface IDog : IAnimal
{
[OperationContract]
string DogSay();
}
} .服务的实现
using System;
using System.ServiceModel; namespace WCF.Chapter2.InheritanceProxyChaining.Host
{
public class Service : IDog
{
public string AnimalSay()
{
return "动物会叫会走路...";
} public string DogSay()
{
return "小狗汪汪叫...";
}
}
} .服务寄宿
using System;
using System.ServiceModel; namespace WCF.Chapter2.InheritanceProxyChaining.Host
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(Service)))
{
host.Opened += delegate
{
Console.WriteLine("服务已开启...");
};
host.Open(); Console.ReadLine();
} Console.WriteLine("服务已关闭...");
Console.ReadLine();
}
}
} .终结点配置 契约使用IDog的契约来发布服务
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MEX">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors> <services>
<service name="WCF.Chapter2.InheritanceProxyChaining.Host.Service" behaviorConfiguration="MEX">
<host>
<baseAddresses>
<add baseAddress="http://loacalhost:8000/"/>
</baseAddresses>
</host> <endpoint address="http://localhost:8001/Dog" binding="basicHttpBinding" contract="WCF.Chapter2.InheritanceProxyChaining.Host.IDog"></endpoint>
</service>
</services>
</system.serviceModel>
</configuration>
b. 客户端
.契约继承 只有命名空间不一样而已
using System;
using System.ServiceModel; namespace WCF.Chapter2.InheritanceProxyChaining.Client
{
[ServiceContract]
public interface IAnimal
{
[OperationContract]
string AnimalSay();
} [ServiceContract]
public interface IDog : IAnimal
{
[OperationContract]
string DogSay();
}
}
. 客户端代理链的实现
using System;
using System.ServiceModel; namespace WCF.Chapter2.InheritanceProxyChaining.Client
{
//clientbase<T> T使用最具体的接口
public class AnimalClientProxy : ClientBase<IDog>, IAnimal
{
public string AnimalSay()
{
return base.Channel.AnimalSay();
}
}
//代理链继承上一级代理实现
public class DogClientProxy : AnimalClientProxy, IDog
{
public string DogSay()
{
return base.Channel.DogSay();
}
}
}
. 本地调用最终呈现出了面向对象的多态,本地化之后就是CLR的内容了,能实现面向对象的特性也是正常的
using System;
using System.ServiceModel; namespace WCF.Chapter2.InheritanceProxyChaining.Client
{
class Program
{
static void Main(string[] args)
{
using (AnimalClientProxy animalProxy = new AnimalClientProxy())
{
Console.WriteLine(animalProxy.AnimalSay());
Console.WriteLine();
} using (AnimalClientProxy animalProxy1 = new DogClientProxy())
{
Console.WriteLine(animalProxy1.AnimalSay());
Console.WriteLine();
} using (DogClientProxy dogProxy = new DogClientProxy())
{
Console.WriteLine(dogProxy.AnimalSay());
Console.WriteLine(dogProxy.DogSay());
Console.WriteLine();
} Console.ReadLine();
}
}
} .客户端终结点 用的也是最具体的契约
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MEX">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors> <services>
<service name="WCF.Chapter2.InheritanceProxyChaining.Host.Service" behaviorConfiguration="MEX">
<host>
<baseAddresses>
<add baseAddress="http://loacalhost:8000/"/>
</baseAddresses>
</host> <endpoint address="http://localhost:8001/Dog" binding="basicHttpBinding" contract="WCF.Chapter2.InheritanceProxyChaining.Host.IDog"></endpoint>
</service>
</services>
</system.serviceModel>
</configuration>

wcf服务契约代理链的更多相关文章

  1. WCF分布式开发步步为赢(6):WCF服务契约继承与分解设计

    上一节我们学习了WCF分布式开发步步为赢(5)服务契约与操作重载部分.今天我们来继续学习WCF服务契约继承和服务分解设计相关的知识点.WCF服务契约继承有何优势和缺点?实际项目里契约设计有什么原则和依 ...

  2. WCF数据契约代理和已知类型的使用

    using Bll; using System; using System.CodeDom; using System.Collections.Generic; using System.Collec ...

  3. wcf服务契约继承

    a. 服务端 .契约 使用了继承 using System; using System.ServiceModel; namespace WCF.Chapter2.InheritanceReworked ...

  4. wcf服务契约的重载

    a. 服务端 .服务端 契约用OperationContract的Name实现重载 using System; using System.Collections.Generic; using Syst ...

  5. 跟我一起学WCF(6)——深入解析服务契约[下篇]

    一.引言 在上一篇博文中,我们分析了如何在WCF中实现操作重载,其主要实现要点是服务端通过ServiceContract的Name属性来为操作定义一个别名来使操作名不一样,而在客户端是通过重写客户端代 ...

  6. 跟我一起学WCF(5)——深入解析服务契约[上篇]

    一.引言 在上一篇博文中,我们创建了一个简单WCF应用程序,在其中介绍到WCF最重要的概念又是终结点,而终结点又是由ABC组成的.对于Address地址也就是告诉客户端WCF服务所在的位置,而Cont ...

  7. 客户端使用自定义代理类访问WCF服务 z

    通常在客户端访问WCF服务时,都需要添加服务引用,然后在客户端app.config或 web.config文件中产生WCF服务的客户端配置信息.若是每添加一个服务都是这样做,这样势必会将比较麻烦,能否 ...

  8. 客户端使用自定义代理类访问WCF服务

    通常在客户端访问WCF服务时,都需要添加服务引用,然后在客户端app.config或web.config文件中产生WCF服务的客户端配置信息.若是每添加一个服务都是这样做,这样势必会将比较麻烦,能否简 ...

  9. 实现jquery.ajax及原生的XMLHttpRequest调用WCF服务的方法

    废话不多说,直接讲解实现步骤 一.首先我们需定义支持WEB HTTP方法调用的WCF服务契约及实现服务契约类(重点关注各attribute),代码如下: //IAddService.cs namesp ...

随机推荐

  1. Mysql-表关系

    表关系分为三种:一对一,一对多,多对多 一对多:一个学院对应多个学生,而一个学生只对应一个学院   --  这儿classroom 是代表的学院. -- 一对多 - A表的一条记录 对应 B 表多条记 ...

  2. [Delphi] 快速获取文件大小

    function GetFileSize(const fName: AnsiString): Int64; var hFile: THandle; begin hFile := _lopen(PAns ...

  3. UVA127

    模拟游戏,规则如下把卡牌一张接一张,从左到右依次摊开,不可以重叠,每当某张卡片和左边(左边第三张)卡片匹配,它就能放到另外一张卡片上,匹配的规则是他们有一样的级别或者花色,在每次移动完成以后,还需要再 ...

  4. leetcode949

    public class Solution { public string LargestTimeFromDigits(int[] A) { ); ; ; foreach (var nums in l ...

  5. 切换svn登录账户

    右键-->TortoiseSVN-->设置 找到:点击已缓存数据 在认证数据一栏点击:清空

  6. iPhone launch screen,self.view.frame.size

    在工程文件中找到以下设置 "Launch Screen File"只支持iOS8以上版本,如果用之,则self.view.frame.size返回的结果为正常的当前view尺寸. ...

  7. 迷你MVVM框架 avalonjs 学习教程17、avalon的一些配置项

    本章节,主要是介绍avalon.config方法,通过它来制定一些更贴心的功能. 一般情况下,我们在使用ms-controller绑定时,需要添加一个ms-controller类名,目的是为了防止网速 ...

  8. scala -- 层级

    层级 层级的顶端是Any 类,定义了如下方法 final def ==(that:Any):Boolean final def !=(that:Any):Boolean def equals(that ...

  9. 多个jsp页面共享Java bean

    通过jsp的内置对象—request对象获取参数: 通过超链接传参: 例:把a.jsp中i的值传到b.jsp中: 在a.jsp页面中的核心代码为: <a href="b.jsp?i=1 ...

  10. git hg提交拉取

    工作总结web_acl 535 git clone “ssh://git@outergit.yonyou.com:49622/esn_web/web_acl.git" 600 git bra ...