简体   繁体   English

使用 WCF 客户端 + cookie 进行 Web 服务调用

[英]Making web service calls with WCF client + cookies

Been implementing the Basic security Authentication in a WCF Service.WCF Service.实现Basic security Authentication WCF Service.

Managed to get the .ASPXCookie from the web service. .ASPXCookie从 Web 服务获取.ASPXCookie But, how to pass along the received cookie back to the next request?但是,如何将接收到的 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"];
    }
}

I tried to print the SharedCookie and was successful in it.我尝试打印SharedCookie并且成功了。 It looks something like,它看起来像,

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

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

To add a Cookie header to the WCF request in the current context given that you have the cookie string already:假设您已经拥有 cookie 字符串,要在当前上下文中向 WCF 请求添加 Cookie 标头:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM