wcf服务契约的重载
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服务契约的重载的更多相关文章
- WCF分布式开发步步为赢(6):WCF服务契约继承与分解设计
上一节我们学习了WCF分布式开发步步为赢(5)服务契约与操作重载部分.今天我们来继续学习WCF服务契约继承和服务分解设计相关的知识点.WCF服务契约继承有何优势和缺点?实际项目里契约设计有什么原则和依 ...
- wcf服务契约代理链
意图:为了是客户端代理呈现出面向对象的多态的特征 a. 服务端 .契约 实现了契约的继承这个在服务端是一点问题没有,因为oprationcontract可以继承,虽然DataContract不能实现继 ...
- wcf服务契约继承
a. 服务端 .契约 使用了继承 using System; using System.ServiceModel; namespace WCF.Chapter2.InheritanceReworked ...
- WCF分布式开发步步为赢(5)服务契约与操作重载
继上一节WCF分布式开发步步为赢系列的(4):WCF服务可靠性传输配置与编程开发,本节我们继续学习WCF分布式开发步步为赢的第(5)节:服务契约与操作重载.这里我们首先讲解OOP面向对象的编程中方法重 ...
- 重温WCF之构建一个简单的WCF(一)(2)通过Windows Service寄宿服务和WCF中实现操作重载
参考地址:http://www.cnblogs.com/zhili/p/4039111.html 一.如何在Windows Services中寄宿WCF服务 第一步:创建Windows 服务项目,具体 ...
- 跟我一起学WCF(6)——深入解析服务契约[下篇]
一.引言 在上一篇博文中,我们分析了如何在WCF中实现操作重载,其主要实现要点是服务端通过ServiceContract的Name属性来为操作定义一个别名来使操作名不一样,而在客户端是通过重写客户端代 ...
- 跟我一起学WCF(5)——深入解析服务契约[上篇]
一.引言 在上一篇博文中,我们创建了一个简单WCF应用程序,在其中介绍到WCF最重要的概念又是终结点,而终结点又是由ABC组成的.对于Address地址也就是告诉客户端WCF服务所在的位置,而Cont ...
- wcf服务编程(第3版)文摘
第1章 wcf基础 什么是wcf: System.ServiceModel.dll 服务 服务的执行边界: proxy 地址:http/https,tcp,ipc,peer newwork,msmq, ...
- 实现jquery.ajax及原生的XMLHttpRequest调用WCF服务的方法
废话不多说,直接讲解实现步骤 一.首先我们需定义支持WEB HTTP方法调用的WCF服务契约及实现服务契约类(重点关注各attribute),代码如下: //IAddService.cs namesp ...
随机推荐
- uva-167-枚举
题意:八皇后问题,要求选取的总和最大 #include<stdio.h> #include<iostream> #include<sstream> #include ...
- win10 + Ubuntu 双系统,重装后的引导修复,时间调整和启动项调整
▶ 原先为 win10 + Ubuntu 双系统,使用 grub2 作引导,在重装了 win10 (大作死升到了1803)后系统重写了引导,启动项里找不到 Ubuntu,需要修复. ● 参考[http ...
- maven下载与配置
转自:https://www.cnblogs.com/jdys/p/3770534.html 1.访问官网:从maven官网下载maven http://maven.apache.org/downlo ...
- thymeleaf的使用
1.导包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...
- MyEclipse: Java代码与UML自动转换
第一步:新建UML2 第二步:拖拽左边的代码向右侧
- xml 创建 和 处理 及其修改
#创建xml import xml.etree.ElementTree as ET new_xml = ET.Element('namelist') personinfo = ET.SubElemen ...
- ASCII字符串互换
//ASCII码转成字符: var a:String=String.fromCharCode(97); trace(a);//输出:a //字符转成ASCII码: var str:String = “ ...
- 8 并发编程-(线程)-多线程与多进程的区别&Thread对象的其他属性或方法
1.开启速度 在主进程下开启线程比 开启子进程快 # 1 在 主进程下开启线程 from threading import Thread def work(): print('hello') if ...
- Java synchronized(this)锁住的是什么
synchronized锁住的是括号里面的对象,而不是代码. 对于非static的synchronized方法,锁的就是对象本身,也就是this.
- 使用sqldeveloper连接服务器端数据库