我学WCF之旅(二)

原文:Endpoint Overview

 

我在学习这一章节的时候着重验证了下通信时Endpoint的Address和Binding必须匹配才能够通信。

我没有原作者提供的Sample,而是用了上次的Solution.

修改如下:

1.在Hosting 项目里加了Address,变成 

Uri  httpBaseAddress = new Uri(http://localhost:8888/generalCalculator); 

Uri tcpBaseAddress = new Uri("net.tcp://localhost:9999/generalCalculator"); 

当然了不同的地址需要的Binding 也不一样:  

BasicHttpBinding httpbinding = new BasicHttpBinding();  

NetTcpBinding tcpbinging = new NetTcpBinding();

host.AddServiceEndpoint(

typeof(ICalculator), httpbinding, string .Empty); typeof(ICalculator), tcpbinging, string.Empty);

host.AddServiceEndpoint(

保存->Build->OPen Folder in Windows Explorer -> using Administrator to run Hosting.exe in bin/debug.

 

2.Client项目

我们已经在代码中更新了Service,这里也需要更新你的Service Reference 里的Service.

因为得我端口该了,所以我直接删了原来的Service Reference ,新添加了一个。但是在我新加的时候

在Add Service Reference dialog里的Address栏里,我试了一下几种

(1) http://localhost:8888/generalCalculator   能找到,可以添加

(2) net.tcp://localhost:9999/generalCalculator   不能找到

(3) http://localhost:8887/generalCalculator 不能找到

(4) http://localhost/generalCalculator  不能找到

(5) http://localhost  不能找到

 

里面应该有什么规则,还不知道,后续..

 

我可以通过方案1找到我的Service,就在Client里写了2种Code 来Invoke 这个Service。

需要注意的地方:Binding 和Address要匹配 

 

  

 

 string.Empty*这里的含义,The address for the endpoint added. This can be an absolute or relative URI. If it is a relative URI, one of the base address of the ServiceHost (depending on the binding protocol) is used as the endpoint's base address.来自MSDN


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值