制作与WCF客户端+饼干Web服务调用饼干、客户端、WCF、Web

2023-09-03 06:07:17 作者:微甜主义

贯彻执行基本安全认证 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 并成功地吧。 它看起来是这样,

".ASPXAUTH=E499CA76EAC178A96BE5CA1E314CC90E0A6F9B95AD221EF5AD7D43598E701DC034D40904DBB8ECFBFB3EA21F2597D3C8DAB9B19A0491FD5858E9F0A4B6DC6E6A980FBB4CCADE191855A029CF8236C6890BEE28665C236992632807D1021AA138;到期=周二,07 - 2014年6点22分22秒格林尼治标准​​时间;路径= /;仅Http

现在的问题是如何通过使用WCF客户端在我的下一个请求此cookie信息 - authClient

解决方案 java 怎么调用.net wcf服务,怎么生成客户端代码

要一个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);