日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
技巧掌握之WCF獲取客戶端IP

WCF在實際應(yīng)用中,可以發(fā)現(xiàn)它能夠幫助我們實現(xiàn)許多功能需求。在這里我們就為大家詳細講解一下有關(guān)WCF獲取客戶端IP的實現(xiàn)方法。#t#

成都創(chuàng)新互聯(lián)長期為1000+客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為嵐皋企業(yè)提供專業(yè)的網(wǎng)站設(shè)計制作、成都做網(wǎng)站,嵐皋網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。

在公司的一個項目里面,使用WCF做通訊,里面需要取得使用WCF獲取客戶端IP,在服務(wù)器上做進一步的處理,但是讓人很失望的是WCF 3.0 里面并不能支持這個功能。還好,微軟在3.5的新版WCF中提供了這個方法。

不說廢話,直接看如何實現(xiàn)。
簡單定義一個WCF獲取客戶端IP的服務(wù):

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.Text;
  7. namespace ClientInfoSample
  8. {
  9. [ServiceContract]
  10. public interface IService
  11. {
  12. [OperationContract]
  13. string GetData(string value);
  14. }
  15. }

在建立通道之后按照可以實現(xiàn)WCF獲取客戶端IP:

 
 
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.Text;
  7. using System.ServiceModel.Channels; 
  8. namespace ClientInfoSample
  9. {
  10. public class MyService : IService
  11. {
  12. public string GetData(string value)
  13. {
  14. OperationContext context = 
    OperationContext.Current;
  15. MessageProperties essageProperties 
    = context.IncomingMessageProperties;
  16. RemoteEndpointMessageProperty endpointProperty =
  17. messageProperties [RemoteEndpoint
    MessageProperty.Name]
  18. as RemoteEndpointMessageProperty;
  19. return string.Format("Hello {0}! 
    Your IP address is {1} and your 
    port is {2}", value, endpointProperty.
    Address, endpointProperty.Port);
  20. }
  21. }
  22. }
  23. config:
  24. behaviorConfiguration="ClientInfoSample.
    MyServiceBehavior">
  25. Design_Time_Addresses/ClientInfoSample/MyService/" />
  26.  contract="ClientInfoSample.IService">
  27. "mexHttpBinding" contract="IMetadataExchange"/>
  28. .MyServiceBehavior">
  29. DetailInFaults="False" />

以上就是有關(guān)WCF獲取客戶端IP的實現(xiàn)方法。


名稱欄目:技巧掌握之WCF獲取客戶端IP
文章分享:http://www.5511xx.com/article/dpssseh.html