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.管理后台 配置内网测试服务器 ...
随机推荐
- Visual Studio各版本工程文件之间的转换 [转载]
原网址:http://www.cnblogs.com/jmliao/p/5594179.html Visual Studio各版本工程文件之间的转换 由于VS版本比较多,低版本无法直接打开高版本的 ...
- BZOJ 3670 NOI2014 动物园 KMP+dp
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3670 题意概述:令num[i]表示字符串由1~i的字符形成的前缀中不相重叠的相同前后缀的数 ...
- 最短路径——Dijkstra算法
一.相关定义 最短路径:从图中的某个顶点出发到达另外一个顶点的所经过的边的权重和最小的一条路径. 地位:Dijkstra算法是很有代表性的最短路算法,在很多专业课程中都作为基本内容有详细的介绍,如数据 ...
- Windows下LATEX排版论文攻略—CTeX、JabRef使用心得
笔者刚刚接触到TEX排版,相关知识完全空白,用了两天时间学习并完成了一篇论文的完整排版. 期间遇到不少小问题,着实辛苦,分享至上,现将其解决办法总结归纳,共同学习. 一.工具介绍 TeX是一个很好排版 ...
- 【iOS开发】IOS界面开发使用viewWithTag:(int)findTag方法获取界面元素
http://blog.csdn.net/lxp1021/article/details/43952551 今天在开发OS界面的时候,遇到通过界面UIview viewWithTag:(int)fin ...
- SQL SERVER 时间相关操作笔记
1.DATEADD函数: A. MSDN上的示例:http://msdn.microsoft.com/zh-cn/library/ms186819%28v=sql.90%29.aspx
- IDEA无法新建GUI Form文件
因为最近想开发一个IDEA的插件,所以在开发的过程中就需要创建Swing GUI Form文件.但是在项目中右键New中始终就是没有“GUI Form”这个选项,然后自己琢磨寻思着是不是没有启用Swi ...
- C++ Profiler工具之初体验
http://www.cnblogs.com/likwo/archive/2012/12/20/2826988.html 转 http://www.cnblogs.com/lenolix/archiv ...
- 【转】关于Java并发编程的总结和思考
一.前言 就是想学习Java并发编程了,所以转载一下这篇认为还不错的博客~ 二.正文 编写优质的并发代码是一件难度极高的事情.Java语言从第一版本开始内置了对多线程的支持,这一点在当年是非常了不起的 ...
- 【Python】Python—判断变量的基本类型
type() >>> type(123)==type(456) True >>> type(123)==int True >>> type('ab ...