如何检测IsOneWay设置为true

时间:2016-11-08 10:20:34

标签: c# asp.net

作为对以下问题的跟进,我得到了同样的错误。我想检测到我处于其中一种情况,然后避免访问servervariables集合。现在我已经在try catch中获得了代码 - 但必须有更好的方法来实现它。

[OperationContract(IsOneWay = true)]
public void someFunction()
{
}

一些名为的代码:

    protected string GetWebClientIpAddress(HttpContext context)
    {
        try
        {
            string ipAddress = context.Request.ServerVariables.AllKeys.Contains("HTTP_X_FORWARDED_FOR")
                ? context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
                : null;

            if (!string.IsNullOrEmpty(ipAddress))
            {
                string[] addresses = ipAddress.Split(',');
                if (addresses.Length != 0)
                    return addresses[0];
            }
            return context.Request.ServerVariables.AllKeys.Contains("REMOTE_ADDR") ? context.Request.ServerVariables["REMOTE_ADDR"] : null;
        }
        catch (Exception ee)
        {
            _logger.Error("Error getting request remote IP", ee);
            return "Error getting remote ip: " + ee.Message;
        }
    }

原始问题: HttpRequest.ServerVariables throws ArgumentException in WCF with IIS7

0 个答案:

没有答案
相关问题