客户端添加服务的时候没有什么太需要注意的地方。写入你本机的ip或127.0.0.1或localhost加上你监听的端口号再加上mex(请求元数据)就OK了。
在添加引用和调用的时候宿主程序一定要运行,应为SL访问的时候是通过你监听的端口进数据通信的。

Code
[http://www.xueit.com]
1 private void btnClick_Click(object sender, RoutedEventArgs e)
2 {
3
4 ServiceReference1.ChatServiceClient sc;
5 EndpointAddress ea = new EndpointAddress("net.tcp://localhost:4503/Service");
6 BindingElement metaElement = new TcpTransportBindingElement();
7 CustomBinding metaBind = new CustomBinding(metaElement);
8
9
10 sc = new ServiceReference1.ChatServiceClient(metaBind, ea);
11 sc.JoinAsync("测试用户名");
12 sc.JoinCompleted = (se, args) =>
13 {
14 MessageBox.Show(args.Result[0]);
15 };
16 }
EndpointAddress ea = new EndpointAddress("net.tcp://localhost:4503/Service");
需要注意的是net.tcp://localhost:4503/Service这个终结点的地址是你ip+监听的端口+宿主程序app.config中定义的终结点地址
<endpoint
address="Service" binding="customBinding"
contract="WebChat.Service.IChatService"
bindingConfiguration="WebChat.Service.ChatService1" >
</endpoint>
下载地址:http://download.csdn.net/source/1910480
精彩图集