问题描述
贯彻执行基本安全认证
在 WCF服务。
设法获得 .ASPXCookie
从Web服务。但是,如何沿着接收cookie的传递到下一个要求吗?
VAR authClient =新MovieDbClient();
使用(新OperationContextScope(authClient.InnerChannel))
{
的isValid = authClient.Login(username的,密码*);
如果(参考isValid)
{
VAR响应= (Htt$p$psponseMessageProperty)OperationContext.Current.IncomingMessageProperties[Htt$p$psponseMessageProperty.Name];
sharedCookie = response.Headers [设置Cookie];
}
}
我试图打印 SharedCookie
并成功地吧。它看起来是这样,
现在的问题是如何通过使用WCF客户端在我的下一个请求此cookie信息 - authClient
要一个Cookie头添加到在目前情况下的WCF请求,因为你已经在cookie字符串:
VAR道具=新的Htt prequestMessageProperty();
prop.Headers.Add(Htt的prequestHeader.Cookie,sharedCookie);
OperationContext.Current.OutgoingMessageProperties.Add(Htt的prequestMessageProperty.Name,道具);
Been implementing the Basic security Authentication
in a WCF Service.
Managed to get the .ASPXCookie
from the web service. But, how to pass along the received cookie back to the next request?
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.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
?
To add a Cookie header to the WCF request in the current context given that you have the cookie string already:
var prop = new HttpRequestMessageProperty();
prop.Headers.Add(HttpRequestHeader.Cookie, sharedCookie);
OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, prop);
这篇关于制作与WCF客户端+饼干Web服务调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!