造轮子:WCF实现客户端和服务端
2016-02-17 22:17
375 查看
http://www.cnblogs.com/jakeqian/archive/2011/03/23/1992445.html
service side
1.定义ServiceContract:
2.new a ServiceHost
3. add endpoint
client side: get proxy, service 调用
bdc = new BaseDataClient(new BasicHttpBinding(), new EndpointAddress(Configurator.GetConfigValue("stsurl")));
<add key="stsurl" value="http://192.168.100.1:8888/CoreData.svc" />
service side
1.定义ServiceContract:
2.new a ServiceHost
3. add endpoint
using System.ServiceModel; namespace Service { class Program { static void Main(string[] args) { Uri address = new Uri("http://localhost:8000/myservice"); using (ServiceHost host = new ServiceHost(typeof(MyService), address)) //MyService是服务方法的类库名称 { host.AddServiceEndpoint(typeof(IMyService), new BasicHttpBinding(), address); //IMyService是服务接口类库名称 host.Open(); Console.ReadLine(); } } } [ServiceContract] public interface IMyService { [OperationContract] string GetService(); } public class MyService : IMyService { public string GetService() { return "Got Service!"; } } }
client side: get proxy, service 调用
using System.ServiceModel; namespace Client { class Program { static void Main(string[] args) { IMyService proxy = ChannelFactory<IMyService>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://localhost:8000/myservice")); Console.WriteLine(proxy.GetService()); Console.ReadLine(); } } [ServiceContract] public interface IMyService { [OperationContract] string GetService(); } }
bdc = new BaseDataClient(new BasicHttpBinding(), new EndpointAddress(Configurator.GetConfigValue("stsurl")));
<add key="stsurl" value="http://192.168.100.1:8888/CoreData.svc" />
相关文章推荐
- C#中的内存分配
- 史上最全:ant多渠道打包安卓工程(一)
- 210 Course Schedule II
- html5语义化标签使用规范
- bootstrap排版、代码、表格
- 学习笔记------数据结构(C语言版)数组的顺序存储
- html5视音频标签参考.md
- HDU5573 Binary Tree
- android/linux进程间通信
- Android Studio的开发视图中,顶部工具栏不见了如何设置回来
- 信息不对称状态下的动态零和博弈
- .NET/Mysql-petatoco连接mysql数据库
- 小程序20
- HTTP协议详解
- C++ virtual函数 实现机制
- 1023. Have Fun with Numbers (20)
- linux(centos)搭建SVN服务器
- iOS实现View镂空效果
- 控件不接收用户交互的情况以及事件响应顺序
- ios 短音效的使用