WCF 宿主里面显示客户端信息
来源:互联网 发布:程序员必备生活用品 编辑:程序博客网 时间:2024/06/06 01:52
废话不多说,一直粘代码。
Business 端代码
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ServiceModel;namespace WCFBusiness{ [ServiceContract] public interface IDemo { [OperationContract] string GetMessage(string value); }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ServiceModel;using System.ServiceModel.Channels;namespace WCFBusiness{ public class Demo : IDemo { public string GetMessage(string value) { OperationContext current = OperationContext.Current; MessageProperties messageProperties = current.IncomingMessageProperties; RemoteEndpointMessageProperty endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; string clientInfo = "IP:" + endpointProperty.Address + "---- 端口:" + endpointProperty.Port; if (RecieveMessageEvent != null) { RecieveMessageEvent(clientInfo); } return string.Format("Hello {0}! Your IP address is {1} and your port is {2}", value, endpointProperty.Address, endpointProperty.Port); } public static event Action<string> RecieveMessageEvent; }}
Service 端
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ServiceModel;using WCFBusiness;namespace WCFService{ class Program { static void Main(string[] args) { using (ServiceHost sh = new ServiceHost(typeof(Demo))) { try { sh.Open(); Console.WriteLine("服务成功启动....."); WCFBusiness.Demo.RecieveMessageEvent += new Action<string>(Demo_RecieveMessageEvent); Console.ReadLine(); sh.Close(); } catch (Exception ioe) { Console.WriteLine(ioe.Message); Console.ReadLine(); } } } static void Demo_RecieveMessageEvent(string obj) { Console.WriteLine(obj+"---------已成功连接"); } }}
App.config
<?xml version="1.0" encoding="utf-8" ?><configuration> <system.serviceModel> <services> <service name="WCFBusiness.Demo" behaviorConfiguration="demoBehavior"> <endpoint address="net" binding="netTcpBinding" bindingConfiguration="demoBinding" contract="WCFBusiness.IDemo" /> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="net.tcp://192.168.18.133:1235/Demo"/> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name="demoBehavior"> <serviceDebug includeExceptionDetailInFaults="True" /> <serviceMetadata httpGetEnabled="false" /> <serviceThrottling maxConcurrentSessions="10000" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <netTcpBinding> <binding name="demoBinding"> <security mode="None"/> </binding> </netTcpBinding> </bindings> </system.serviceModel></configuration>
Client 端
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace WCFClient{ class Program { static void Main(string[] args) { DemoService.DemoClient client = new DemoService.DemoClient(); Console.WriteLine(client.GetMessage("xiao hui")); Console.ReadLine(); } }}
由于本人一搞技术的,文字表达能力不怎么强,所以说明还是不说,怕说了你们会看不懂,所以才直接粘代码,如果有不懂的可以留言问我。
- WCF 宿主里面显示客户端信息
- WCF——1.2 WCF服务、控制台宿主、控制台客户端
- WCF——1.3 WCF服务、WinForm宿主、WinForm客户端
- WCF宿主
- WCF服务类库、宿主、web客户端配置
- WCF学习笔记二:客户端调用控制台宿主程序
- 强大的WCF宿主
- WCF 宿主问题
- WCF服务自宿主
- WCF创建宿主程序
- WCF中如何得到客户端信息
- WCF的宿主 - -WCF的配置文件
- WCF入门教程三[WCF的宿主]
- WCF入门教程三[WCF的宿主]
- WCF宿主与服务托管
- WCF的宿主(服务器)
- WCF宿主与服务托管
- WCF 基于 WinForm 宿主 发布
- org.hibernate.exception.ConstraintViolationException: could not insert
- webservice(一)---c#开发webservice
- java中的值传递和引用传递
- ExtJS Ajax简单用法
- 线程基础之产生线程
- WCF 宿主里面显示客户端信息
- IE,FF客户端浏览器缓存机制and服务器设置的expires, Cache-Control,no-cache,no-store机制
- 理解OpenGL拾取模式(OpenGL Picking)
- Android 嵌入式数据库SQLite练习小记录
- HDU 3723
- webconfig详解
- object-c 中的 self 含义
- Lucene增强功能:Payload的应用
- 玩微博的朋友们请关注我一下,@爪哇米工作室,新浪和腾讯的都可以!