WCF身份验证CookieContainer为空 - 通用Windows应用程序

时间:2016-04-06 10:30:01

标签: wcf cookies portable-class-library windows-10-universal cookiecontainer

我在通用Windows应用上登录WCF身份验证服务,当我尝试访问CookieContainer时,它是空的。

Windows 8.1应用程序上的相同代码工作正常。

对于basicbindings,我将AllowCookies设置为true。这些服务位于PCL中,允许我使用CookieContainer属性,当我使用“添加服务参考”时,该属性不可用。直接在通用Windows应用程序上。

(UWP App)MainPage

var binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.AllowCookies = true;

new ClassLibrary1.Class1().Login(binding);

(PCL)Class1

public class Class1
{
    public void Login(BasicHttpBinding binding)
    {
        var Client = new ServiceReference1.AuthenticationServiceClient(binding, new EndpointAddress("*****.svc"));

        Client.LoginAsync("*****", "*****", null, false);

        Client.LoginCompleted += (sender, args) =>
        {
            if (args.Result)
            {
                CookieContainer CookieContainer = Client.CookieContainer;
                CookieCollection Cookies = CookieContainer.GetCookies(Client.Endpoint.Address.Uri);

                Cookie Cookie = Cookies[".ASPXAUTH"];
            }
        };
        }
    }
}

0 个答案:

没有答案