我使用下面的代碼在我的服務獲取客戶端的IP地址在WCF與wsDualHttpBinding
public class HeartBeat : IHeartBeat
{
public string GetData()
{
OperationContext context = OperationContext.Current;
MessageProperties prop = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpoint =
prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string ip = endpoint.Address;
return "IP address is: " + ip;
}
}
我注意到,如果我的網絡配置是:
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" />
</protocolMapping>
我能成功獲得IP地址。但是,如果我使用這樣的雙http綁定:
<protocolMapping>
<add binding="wsDualHttpBinding" scheme="http" />
</protocolMapping>
我得到一個空返回。有沒有其他方法可以在wsDualHttpBinding中獲取客戶端的IP地址?預先感謝您
現貨..這是工作。不過我正在電腦名稱,而不是IP地址。無論如何解決這個問題? – Redis1001