VS自带WCF测试客户端简单介绍
来源:互联网 发布:基2fft算法 编辑:程序博客网 时间:2024/05/08 23:10
在目前的二次开发项目中,一些信息是放在客户那里的,只给你一个服务地址,不知道具体有什么方法,每次想调用一个服务不知道能不能实现目前的需求,只能测试。写个测试程序真的划不来,占用时间不说,而且你忙了一上午,发现那个服务,并不是你想要的。只能说白忙了......下面简单介绍一下,从同事那里学到的怎么使用VS自带的测试客户端。操作很简单,但很实用。知道这个的,就不用说了,这篇文章就是帮助那些不知道的小伙伴的......
一个简单的WCF服务端:
契约:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.ServiceModel;
namespace
Wolfy.Contract
{
[ServiceContract(Namespace=
"http://www.wolfy.com"
)]
public
interface
ICalculator
{
[OperationContract]
double
Add(
double
x,
double
y);
}
}
服务:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
Wolfy.Contract;
namespace
Wolfy.Service
{
public
class
CalculatorService : ICalculator
{
#region ICalculator 成员
public
double
Add(
double
x,
double
y)
{
return
x + y;
}
#endregion
}
}
这里就用控制台来承载服务了
控制台代码开启服务:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
Wolfy.Contract;
using
Wolfy.Service;
using
System.ServiceModel;
namespace
Wolfy.Server
{
class
Program
{
static
void
Main(
string
[] args)
{
using
(ServiceHost host =
new
ServiceHost(
typeof
(CalculatorService)))
{
host.Opened +=
delegate
{
Console.WriteLine(
"calculatorService已启动,按任意键停止服务"
);
};
host.Open();
Console.Read();
}
}
}
}
服务端配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?xml version=
"1.0"
?>
<configuration>
<startup>
<supportedRuntime version=
"v4.0"
sku=
".NETFramework,Version=v4.5"
/>
</startup>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name=
"MyServiceBehavior"
>
<serviceMetadata httpGetEnabled=
"true"
/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name=
"Wolfy.Service.CalculatorService"
behaviorConfiguration=
"MyServiceBehavior"
>
<endpoint contract=
"Wolfy.Contract.ICalculator"
binding=
"wsHttpBinding"
></endpoint>
<host>
<baseAddresses>
<add baseAddress=
"http://127.0.0.1:8888/calculatorservice"
/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
一个简单的WCFdemo算完成了,现在开启服务....
打开VS测试客户端
在开发人员命令提示中输入:wcftestclient回车
然后右键我的项目:输入你的服务地址,当然这里你的服务要在开启的状态。
为参数赋值:
结果:
很简单吧,虽然不是很高深的东西,但很实用,如果您觉得对你有所帮助,那就【推荐】一下吧,毕竟大家知道才是真的知道。
0 0
- VS自带WCF测试客户端简单介绍
- 【WCF】使用WCF测试客户端
- MySQL自带数据库-information_schema简单介绍
- WCF测试客户端
- WCF测试客户端
- WCF测试客户端(WcfTestClient)
- WCF测试客户端(WcfTestClient)
- dumpbin(vs自带)
- ArcGIS10.1自带的数据库客户端介绍
- WCF测试客户端(WCF Test Client)
- wcf的简单介绍
- HADOOP自带测试类介绍及使用
- WCF 测试客户端 (WcfTestClient.exe)
- VS连接VS自带的开发测试版SQL,C#
- VC6.0 自带小工具 简单介绍
- 简单介绍JDK1.6自带的工具
- MarkDown自带介绍
- VS 自带打包程序
- QT——QSqlDatabase
- 浅谈图像处理方向的就业前景 & 心得感悟 & 一些相关期刊
- linux系统打开文件数过多的解决办法
- 深入学习python (七) 如何用python调用C/C++接口
- Android中的动态加载机制
- VS自带WCF测试客户端简单介绍
- CRBM实验设计及结果(version1)
- 点击按钮实现表单的显示,提交数据后表单消失
- Asp.net读取AD域信息的方法<转>
- Eclipse 改变主题
- const对象的位置问题
- Nand flash读写范围的问题
- MyBatis报错处理
- c语言_lesson_5 指针和函数