博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在WCF服务中获取客户端的IP地址和端口号
阅读量:6946 次
发布时间:2019-06-27

本文共 955 字,大约阅读时间需要 3 分钟。

版权声明

请尊重原创作品。转载请保持文章完整性,并以超链接形式注明原始作者“”和地址,方便其他朋友提问和指正。

  1. using System;  
  2. using System.ServiceModel;  
  3. using System.ServiceModel.Channels;  
  4.   
  5. namespace WcfService3  
  6. {  
  7.     // 注意: 如果更改此处的类名“Service1”,也必须更新 Web.config 和关联的 .svc 文件中对“Service1”的引用。  
  8.     public class Service1 : IService1  
  9.     {  
  10.         public string GetData(int value)  
  11.         {  
  12.             //提供方法执行的上下文环境  
  13.             OperationContext context = OperationContext.Current;  
  14.             //获取传进的消息属性  
  15.             MessageProperties properties = context.IncomingMessageProperties;  
  16.             //获取消息发送的远程终结点IP和端口  
  17.             RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;  
  18.             Console.WriteLine(string.Format("Hello {0},You are  from {1}:{2}", value, endpoint.Address, endpoint.Port));  
  19.             return string.Format("Hello {0},You are  from {1}:{2}", value, endpoint.Address, endpoint.Port);  
  20.   
  21.         }  
  22.   
  23.         public CompositeType GetDataUsingDataContract(CompositeType composite)  
  24.         {  
  25.             if (composite.BoolValue)  
  26.             {  
  27.                 composite.StringValue += "Suffix";  
  28.             }  
  29.             return composite;  
  30.         }  
  31.     }  
  32. }  
你可能感兴趣的文章
LeetCode - Populating Next Right Pointers in Each Node
查看>>
管理团队时,怎样保证一直做正确的事?
查看>>
如果应用程序正在通过 <identity impersonate="true"/> 模拟,则标识将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的请求用户。...
查看>>
Oozie入门
查看>>
myeclipse一直bulid workspace 的解决
查看>>
表单元素之搭车系
查看>>
mysql+redis
查看>>
[Android]Dagger2Metrics - 测量DI图表初始化的性能(翻译)
查看>>
sublime开启vim模式
查看>>
Rikka with Chess(规律)
查看>>
【设计模式】迭代器模式
查看>>
MATLAB中imshow()和image()
查看>>
Atitit.eclipse git使用
查看>>
JAVA逆向&反混淆-追查Burpsuite的破解原理(转)
查看>>
cocos2dx 3.1从零学习(一)——入门篇(一天学会打飞机)
查看>>
[CareerCup] 15.4 Types of Join 各种交
查看>>
文档批量格式化之word技能
查看>>
C#~异步编程再续~await与async引起的w3wp.exe崩溃
查看>>
Android屏幕适配全攻略(最权威的官方适配指导)
查看>>
.NET设计模式访问者模式
查看>>