a. 服务端
.服务端 契约用OperationContract的Name实现重载
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text; namespace WCF.Chapter2.Overloading.Host
{
[ServiceContract]
public interface IContract
{
[OperationContract(Name = "say1")]
string say(); [OperationContract(Name = "say2")]
string say(string str);
} }
.服务实现
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text; namespace WCF.Chapter2.Overloading.Host.Service
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“Service1”。
public class Service1 : IContract
{
public string say()
{
return "老鼠扛刀,满街找猫";
} public string say(string str)
{
return str;
}
} }
.服务寄宿
using System;
using System.ServiceModel;
using WCF.Chapter2.Overloading.Host.Service;
namespace WCF.Chapter2.Overloading.Host
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(Service1)))
{
host.Opened += delegate
{
Console.WriteLine("服务已开启...");
};
host.Open();
Console.ReadLine();
} 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.Overloading.Host.Service.Service1" behaviorConfiguration="MEX">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000"/>
</baseAddresses>
</host> <endpoint address="http://localhost:8001/say" binding="basicHttpBinding" contract="WCF.Chapter2.Overloading.Host.IContract"></endpoint>
</service>
</services>
</system.serviceModel>
</configuration>
b. 客户端
.客户端契约 这个很重要需要和服务端分开不能用同一个契约,而是实现了一个等效契约,所以此处说明终结点三要素A,B,C 的A,B必须一模一样但是C只要等效就可以
using System;
using System.ServiceModel; namespace WCF.Chapter2.Overloading.Client
{
[ServiceContract]
public interface IContract
{
[OperationContract(Name = "say1")]
string say(); [OperationContract(Name = "say2")]
string say(string str);
}
}
.客户端代理 本质也是channelfactory.createchannel
using System;
using System.ServiceModel; namespace WCF.Chapter2.Overloading.Client
{
public class ClientProxy : ClientBase<IContract>, IContract
{
public ClientProxy()
{ } public ClientProxy(string configurationName) :
base(configurationName)
{ } public string say()
{
return base.Channel.say();
} public string say(string str)
{
return base.Channel.say(str);
}
}
} .客户端终结点配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:8001/say" binding="basicHttpBinding" contract="WCF.Chapter2.Overloading.Client.IContract"></endpoint>
</client>
</system.serviceModel>
</configuration>
.调用代码
using System;
using System.ServiceModel; namespace WCF.Chapter2.Overloading.Client
{
public class ClientProxy : ClientBase<IContract>, IContract
{
public ClientProxy()
{ } public ClientProxy(string configurationName) :
base(configurationName)
{ } public string say()
{
return base.Channel.say();
} public string say(string str)
{
return base.Channel.say(str);
}
}
}

wcf服务契约的重载的更多相关文章

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

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

  2. wcf服务契约代理链

    意图:为了是客户端代理呈现出面向对象的多态的特征 a. 服务端 .契约 实现了契约的继承这个在服务端是一点问题没有,因为oprationcontract可以继承,虽然DataContract不能实现继 ...

  3. wcf服务契约继承

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

  4. WCF分布式开发步步为赢(5)服务契约与操作重载

    继上一节WCF分布式开发步步为赢系列的(4):WCF服务可靠性传输配置与编程开发,本节我们继续学习WCF分布式开发步步为赢的第(5)节:服务契约与操作重载.这里我们首先讲解OOP面向对象的编程中方法重 ...

  5. 重温WCF之构建一个简单的WCF(一)(2)通过Windows Service寄宿服务和WCF中实现操作重载

    参考地址:http://www.cnblogs.com/zhili/p/4039111.html 一.如何在Windows Services中寄宿WCF服务 第一步:创建Windows 服务项目,具体 ...

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

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

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

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

  8. wcf服务编程(第3版)文摘

    第1章 wcf基础 什么是wcf: System.ServiceModel.dll 服务 服务的执行边界: proxy 地址:http/https,tcp,ipc,peer newwork,msmq, ...

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

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

随机推荐

  1. 一种思路,隐藏input标签,通过label关联

    <label class="btn btn-default btn-file">上传图片 <input hidden type="file" ...

  2. three添加和移除对象

    创建场景在第一章的地方就讲过怎么样创建一个最基本的场景,这里不重复了html:部分 <!doctype html><html lang="en"><h ...

  3. springboot的全局异常通知

    ExceptionHandler:拦截所有通知

  4. plsql 粘贴

    plsql 粘贴

  5. 用yield 实现协程 (包子模型)

    协程是一种轻量级的线程 无需线程上下级的开销, 所有的协程都在一个线程内执行 import time def consumer(name): print('%s is start to eat bao ...

  6. Eclipse launch configuration----Eclipse运行外部工具

    虽然我们已经有了像 Eclipse 这样高级的 IDE,但是我们有时候也是需要在开发的时候使用 Windows 的命令行,来运行一些独立的程序.在两个程序中切换来切换去是很麻烦的.所以 Eclipse ...

  7. UI5-文档-4.18-Icons

    我们的对话框仍然是空的.因为SAPUI5附带了一个包含500多个图标的大图标字体,所以我们将在对话框打开时添加一个图标来问候用户. Preview An icon is now displayed i ...

  8. 超简单,webpack配置

    有看过我的博客的童鞋可能有看到我最近有在利用闲暇时间做一个前后台均涵盖的音乐播放器项目,但是呢,我是一个小小的前端,对后台的了解可以说只停留在很初级的阶段,当然了音乐播放器的音乐列表是后台轮循出来的, ...

  9. win10为什么不能把文件直接拖拽

  10. mysql 列转行

    第一种方法:使用序列化表的方法实现列转行 第一种方法:使用UNION的方法实现列转行 第二种方法:使用序列化表的方法实现列转行