wcf服务契约代理链
意图:为了是客户端代理呈现出面向对象的多态的特征
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服务契约代理链的更多相关文章
- WCF分布式开发步步为赢(6):WCF服务契约继承与分解设计
上一节我们学习了WCF分布式开发步步为赢(5)服务契约与操作重载部分.今天我们来继续学习WCF服务契约继承和服务分解设计相关的知识点.WCF服务契约继承有何优势和缺点?实际项目里契约设计有什么原则和依 ...
- WCF数据契约代理和已知类型的使用
using Bll; using System; using System.CodeDom; using System.Collections.Generic; using System.Collec ...
- wcf服务契约继承
a. 服务端 .契约 使用了继承 using System; using System.ServiceModel; namespace WCF.Chapter2.InheritanceReworked ...
- wcf服务契约的重载
a. 服务端 .服务端 契约用OperationContract的Name实现重载 using System; using System.Collections.Generic; using Syst ...
- 跟我一起学WCF(6)——深入解析服务契约[下篇]
一.引言 在上一篇博文中,我们分析了如何在WCF中实现操作重载,其主要实现要点是服务端通过ServiceContract的Name属性来为操作定义一个别名来使操作名不一样,而在客户端是通过重写客户端代 ...
- 跟我一起学WCF(5)——深入解析服务契约[上篇]
一.引言 在上一篇博文中,我们创建了一个简单WCF应用程序,在其中介绍到WCF最重要的概念又是终结点,而终结点又是由ABC组成的.对于Address地址也就是告诉客户端WCF服务所在的位置,而Cont ...
- 客户端使用自定义代理类访问WCF服务 z
通常在客户端访问WCF服务时,都需要添加服务引用,然后在客户端app.config或 web.config文件中产生WCF服务的客户端配置信息.若是每添加一个服务都是这样做,这样势必会将比较麻烦,能否 ...
- 客户端使用自定义代理类访问WCF服务
通常在客户端访问WCF服务时,都需要添加服务引用,然后在客户端app.config或web.config文件中产生WCF服务的客户端配置信息.若是每添加一个服务都是这样做,这样势必会将比较麻烦,能否简 ...
- 实现jquery.ajax及原生的XMLHttpRequest调用WCF服务的方法
废话不多说,直接讲解实现步骤 一.首先我们需定义支持WEB HTTP方法调用的WCF服务契约及实现服务契约类(重点关注各attribute),代码如下: //IAddService.cs namesp ...
随机推荐
- Django之模板Template
模板介绍 作为Web框架,Django提供了模板,可以很便利的动态生成HTML 模版系统致力于表达外观,而不是程序逻辑 模板的设计实现了业务逻辑(view)与显示内容(template)的分离,一个视 ...
- 动态html处理和及其图像识别
爬虫(Spider),反爬虫(Anti-Spider),反反爬虫(Anti-Anti-Spider) 之间恢宏壮阔的斗争... Day 1 小莫想要某站上所有的电影,写了标准的爬虫(基于HttpCli ...
- uva-10129-欧拉通路
题意:每一个单词的长度最小2,最大1000,单词开头的字母和另外一个单词的末尾一样就可以连接起来,解所有的单词是不是都可以连接起来,没有遗漏的 把每一个单词的第一个字母当成一个结点,最后一个单词也作为 ...
- uva-657-搜索
注意是四个方向(上下左右),不是八个方向,当成了八个方向做,一直wa AC时间:0ms #include<stdio.h> #include<iostream> #includ ...
- JAVA Spring JavaBean 属性值的注入方式( 属性注入, 特殊字符注入 <![CDATA[ 带有特殊字符的值 ]]> , 构造器注入 )
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- django 使用 可视化包-Pyechart
Echarts 是百度开源的一个数据可视化 JS 库,主要用于数据可视化.pyecharts 是一个用于生成 Echarts 图表的类库.实际上就是 Echarts 与 Python 的对接. 本次使 ...
- linux 安装禅道
1. 查看Linux服务器版本信息 # cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 2. 禅道开源版安装包下载 # wge ...
- hadoop配置文件的参数含义说明
#hadoop version 查看版本号 1 .获取默认配置 hadoop2系列配置文件一共包括6个,分别是hadoop-env.sh.core-site.xml.hdfs-site.xml.map ...
- mysql 导入csv 转义
TERMINATED :分隔符 ESCAPED :转义用什么标示,‘’ 不设置转义符 LOAD DATA LOCAL INFILE '/home/tmp/1999/holder.csv' INTO ...
- airway之workflow
1)airway简介 在该workflow中,所用的数据集来自RNA-seq,气道平滑肌细胞(airway smooth muscle cells )用氟美松(糖皮质激素,抗炎药)处理.例如,哮喘患 ...