【问题标题】:Making web service calls with WCF client + cookies使用 WCF 客户端 + cookie 进行 Web 服务调用
【发布时间】:2014-01-24 17:40:50
【问题描述】:

WCF Service. 中实现Basic security Authentication

设法从网络服务获取.ASPXCookie。但是,如何将收到的 cookie 传递回下一个请求?

var authClient = new MovieDbClient();
using (new OperationContextScope(authClient.InnerChannel))
{
    isValid = authClient.Login("userName", "passWord*");
    if (isValid)
    {
        var response = (HttpResponseMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name];
        sharedCookie = response.Headers["Set-Cookie"];
    }
}

我尝试打印SharedCookie 并且成功了。 它看起来像,

".ASPXAUTH=E499CA76EAC178A96BE5CA1E314CC90E0A6F9B95AD221EF5AD7D43598E701DC034D40904DBB8ECFBFB3EA21F2597D3C8DAB9B19A0491FD5858E9F0A4B6DC6E6A980FBB4CCADE191855A029CF8236C6890BEE28665C236992632807D1021AA138; expires=Tue, 07-Jan-2014 06:22:22 GMT; path=/; HttpOnly"

问题是how do I pass this cookie information in my next request using wCF Client - authClient

【问题讨论】:

    标签: c# .net wcf authentication cookies


    【解决方案1】:

    如果您已经拥有 cookie 字符串,则在当前上下文中向 WCF 请求添加 Cookie 标头:

    var prop = new HttpRequestMessageProperty();
    prop.Headers.Add(HttpRequestHeader.Cookie, sharedCookie);
    OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, prop);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    相关资源
    最近更新 更多