【问题标题】:Getting an exception while trying to reach value of the "Set-Cookie" key in C#尝试在 C# 中达到“Set-Cookie”键的值时出现异常
【发布时间】:2015-02-23 14:36:59
【问题描述】:

我想到达来自 wcf 服务的响应的 HTTP / SOAP 标头(请注意,响应是一个对象,而不是 xml 字符串)以获取响应中“Set-Cookie”键的值。我尝试使用HttpResponseMessageProperty 获取标头,但它引发了一个名为 ArgumentException 的异常。

在 ASP.NET 示例中,WebRequestWebResponse 运行良好,但我正在尝试使用 wcf 服务的代理方法在 C# 中编写一个库,因此,我应该使用 HttpResponseMessageProperty .

等待您的帮助。谢谢。

编辑:

我在下面附上了异常的屏幕截图。

【问题讨论】:

    标签: c# web-services wcf session setcookie


    【解决方案1】:
            using (OperationContextScope scope = new OperationContextScope(Parameters.ClientService.InnerChannel))
            {
                var response = Parameters.ClientService.SearchFlight(Parameters.AuthenticationHeader, Operations.CreateSearchRequest(fsf));
    
                var messageProperty = (HttpResponseMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name];
                var sessionId = messageProperty.Headers["Set-Cookie"];
    
                FlightSearchResultDto result = Operations.CreateSearchResult(response, fsf, BaseProvider);
    
                return result;
            }
    

    【讨论】:

      【解决方案2】:

      我认为最好的方法是将该语句包含在 try 'n' catch 语句中并管理异常。

      【讨论】:

      • 我也在做同样的事情,但是有一些错误,我无法从 try-catch 中理解,这真的很麻烦。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-08
      • 1970-01-01
      • 2014-05-16
      • 2019-04-14
      • 1970-01-01
      相关资源
      最近更新 更多