WCF实现客户端和服务端
2024-10-07 16:30:13
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" />
最新文章
- 关于从Activity A跳转到Activity B ,其中Activity A中有一个VideoView,Activity B中有一个MediaPlayer。
- Linux文件类型
- mysql环境搭建
- Android自定义控件(二)
- Android应用中使用AsyncHttpClient来异步网络数据(转载)
- JSP中的Servlet及Filter
- LPCTSTR 用法
- 【转载】jQuery1.5之后的deferred对象详解
- WPF用ShowDialog()弹出窗体时控制该窗体的显示位置,并传值回父窗体
- CSS3之firefox&;safari背景渐变之争 - [前端技术][转]
- How do I list all tables/indices contained in an SQLite database
- Android studio中Rendering Problems不能可视化操作的解决办法
- linux的fork函数
- nginx的autoindex-目录浏览还有其它两个参数
- Java数据结构漫谈-Vector
- 我推荐的一些iOS开发书单
- Python基础---python中的异常处理
- Python学习之dict和set
- less--入门
- 学习笔记:fhq-treap