WCF测试小程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleTest
{
class Program
{
static void Main(string[] args)
{
//发布服务端的主机服务
string url = "http://localhost:8080";
ServiceHost sh = new ServiceHost(typeof(MyService));
Binding bind = new BasicHttpBinding();
sh.AddServiceEndpoint(typeof(IService), bind, url);
sh.Open();
//客户端发送消息,使用服务端的服务
ChannelFactory<IService> cf = new ChannelFactory<IService>(bind);
EndpointAddress ea = new EndpointAddress(url);
IService iservice = cf.CreateChannel(ea);
Student ss = iservice.GetStudent();
Console.WriteLine(ss.StuID);
Console.WriteLine(ss.Name);
Console.WriteLine(ss.Age);
Console.Read();
}
}
/// <summary>
/// 定义服务的协定接口
/// </summary>
[ServiceContract]
public interface IService
{
[OperationContract]
Student GetStudent();
}
/// <summary>
/// 实现服务接口
/// </summary>
public class MyService : IService
{
public Student GetStudent()
{
Student s = new Student();
s.StuID = 123456;
s.Name = "哈哈哈哈";
s.Age = 20;
return s;
}
}
/// <summary>
/// 序列化
/// </summary>
[DataContract]
public class Student
{
private long stuID;
[DataMember]
public long StuID
{
get { return stuID; }
set { stuID = value; }
}
private string name;
[DataMember]
public string Name
{
get { return name; }
set { name = value; }
}
private int age;
[DataMember]
public int Age
{
get { return age; }
set { age = value; }
}
/// <summary>
/// 反序列化时,执行此方法
/// </summary>
/// <param name="ss"></param>
[OnSerializing]
public void hhha(StreamingContext ss)
{
this.Age = this.Age == 20 ? 50 : 88;
}
}
}
WCF测试小程序的更多相关文章
- WCF练习小程序总结
1.什么是WCF 严格的说,WCF就是专门用于服务定制.发布与运行以及消息传递和处理的一组专门类的集合,也就是所谓的“类库”.这些类通过一定方式被组织起来,共同协 作,并为开发者提供了一个统一的编程模 ...
- WordCount 优化版测试小程序实现
Stage1:代码编写+单元测试 Github地址: https://github.com/245553473/wcPro.git PSP表格: PSP PSP阶段 预估耗时(分钟) 实际耗时(分钟) ...
- WordCount优化版测试小程序实现
Github地址:https://github.com/hcy6668/wordCountPro.git PSP表格: PSP PSP阶段 预估耗时(小时) 实际耗时(小时) Planning ...
- WordCount测试小程序的实现
一.GitHub地址: https://github.com/245553473/WordCount 二.PSP表格: PSP PSP阶段 预估耗时(分钟) 实际耗时(分钟) Planning 计划 ...
- python 实现九型人格测试小程序
用python实现九型人格测试,并把测试结果绘制成饼图,实现代码如下: # @Description: 九型人格 import xlrd, matplotlib.pyplot as plt data ...
- 0001_第一个测试小程序Login
# -*- coding:utf-8 -*- user = raw_input("Username:") password = raw_input("Password:& ...
- STM32CubeMX 多通道 ADC DMA 配置 测试小程序
要点: 1.STM32F103C8T6单片机 2.ADC+DMA 多通道 重点是ADC+DMA配置,ADC+DMA配置如下 其他配置略略略略. 然后各位自行直看.ioc文件,生成代码后在while之前 ...
- 微信小程序和微信H5测试中易出Bug的点和注意事项
一.微信小程序 易出Bug的点: 小程序的分享转发功能 背景:小程序项目开发基本完毕也都已经测过几轮,功能上基本没有什么问题,但是上线后却被客户发现通过分享转发小程序给别人,别人无法正常打开的情况 原 ...
- 微信小程序测试的策略和注意事项
一.测试前准备(环境搭建) 1.前端页面 微信Web开发者工具安装.授权测试用的微信号可预览和调试小程序...可参考此文: 微信Web开发者工具-下载.安装和使用图解 2.管理后台 配置内网测试服务器 ...
随机推荐
- 预研报告——MyBatis持久层的demo
一.预研任务介绍和预研目标 任务介绍: 与 Hibernate 相比, MyBatis 是一个半自动化的持久层框架,以轻量级.效率高.原生代而好评如潮.虽然有在分享会上大致讲解,但是还是重新梳理成文字 ...
- Oracle入门书籍推荐
作者:eygle |English [转载时请标明出处和作者信息]|[恩墨学院 OCM培训传DBA成功之道] 链接:http://www.eygle.com/archives/2006/08/orac ...
- 通过NTP(Network Time Protocal)协议进行时间同步
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwUAAAKOCAYAAAD3ZbXWAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjw
- enter & keypress
enter & keypress https://stackoverflow.com/questions/905222/enter-key-press-event-in-javascript ...
- css引入特殊字体
http://www.fontsquirrel.com/tools/webfont-generator ttf格式的字体转换成其他格式的字体 css引入特殊字体建议只是用英文字体,中 ...
- P2730 魔板 Magic Squares
题目背景 在成功地发明了魔方之后,鲁比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 5 题目描述 我们知道魔板的每一个方格都有一种颜色.这8种颜 ...
- 【题解】MUTC2013idiots
我是先知道的这题是FFT然后再做的,知道是FFT其实就是个套路题啦.首先,我们容易发现 \(P = \frac{a}{b}\) 其中a表示合法的方案数,而b表示全部的方案数. b的值即为\(C\lef ...
- AOJ.502 不只是水仙花
不只是水仙花 Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MB Total Submission: 1196 Submi ...
- [Noip2004]虫食算 dfs
搜索问题的关键:优秀的搜索策略以及行之有效的减枝 对于这道题我们阶乘搜肯定不行所以我们按位搜,我们对每一位的三个数进行赋值,然后判解. 对于此一类的搜索乘上一个几十的常数来减枝往往要比直接搜要快得多, ...
- jquery学习总计
1,jquery的基础语法 $(selector).action(); 选择器(selector)查询和查找html元素,action()执行对函数的操作. 2.选择器 id,类,类型,属性,属性值等 ...