WCF獲取客戶端IP正確代碼操作剖析
作者:佚名
我們今天將會在這篇文章中以一段代碼示例來為大家詳細(xì)介紹一下WCF獲取客戶端IP的相關(guān)實(shí)現(xiàn)方法,希望大家可以充分掌握這一技巧。
WCF應(yīng)用方法比較靈活,可以為開發(fā)人員創(chuàng)造一個(gè)跨平臺的解決方案。我們在這里會為大家詳細(xì)講解一下有關(guān)WCF獲取客戶端IP的操作方法,希望對這方面又需要的朋友們可以從中獲得一些幫助。
WCF獲取客戶端IP的簡單方法:
- using System;
- using System.Collections.Generic;
- using System.Linq;using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.Text;
- using System.ServiceModel.Channels;
- namespace ClientInfoSample
- {
- public class MyService : IService
- {
- public string GetData(string value)
- {
- OperationContext context = OperationContext.Current;
- MessageProperties messageProperties = context.IncomingMessageProperties;
- RemoteEndpointMessageProperty endpointProperty =
- messageProperties[RemoteEndpointMessageProperty.Name]
- as RemoteEndpointMessageProperty;
- return string.Format("Hello {0}! Your IP address is {1} and your port is {2}",
- value, endpointProperty.Address, endpointProperty.Port);
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.Text;
- namespace ClientInfoSample
- {
- [ServiceContract]
- public interface IService
- {
- [OperationContract]
- string GetData(string value);
- }
- }
【編輯推薦】
責(zé)任編輯:曹凱
來源:
博客園