public static void SetAuthenticationCookies(this OrganizationWebProxyClient client, CookieCollection cookies)
        {
            var cookieContainer = new CookieContainer();

            foreach (Cookie cookie in cookies)
            {
                cookieContainer.Add(cookie);
            }
            var cookieBehavior = new CookieBehavior(cookieContainer);

            client.Endpoint.EndpointBehaviors.Add(cookieBehavior);
        }
예제 #2
0
    static void Main(string[] args)
    {
        var cookieCont = new CookieContainer();

        using (var svc = new TestServiceReference.TestServiceClient())
        {
            cookieCont.Add(svc.Endpoint.Address.Uri, new Cookie("TestClientCookie", "Cookie Value 123"));
            var behave = new CookieBehavior(cookieCont);
            svc.Endpoint.EndpointBehaviors.Add(behave);
            var data = svc.GetData(123);
            Console.WriteLine(data);
            Console.WriteLine("---");
            foreach (Cookie x in cookieCont.GetCookies(svc.Endpoint.Address.Uri))
            {
                Console.WriteLine(x.Name + "=" + x.Value);
            }
        }
        Console.ReadLine();
    }
예제 #3
0
        public static SortedList getGroupCollection(string webPath, string spCookie, out string error)
        {
            error = "";
            SortedList groups = new SortedList();
            try
            {
                SharepointUserGroupsWCF.UserGroupSoapClient client = new SharepointUserGroupsWCF.UserGroupSoapClient();
                //client.ClientCredentials.Windows.ClientCredential = (NetworkCredential)credentials;
                //client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                client.Endpoint.Address = new EndpointAddress(webPath + "/_vti_bin/usergroup.asmx");

                // -- start new code --
                // add a Cookie Behaviour to inject a cookie into the underlying httpRequest
                CookieBehavior cookieBehaviour = new CookieBehavior(spCookie);
                client.Endpoint.Behaviors.Add(cookieBehaviour);
                // -- end new code --

                XElement groupXml;
                groupXml = client.GetGroupCollectionFromSite();

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(groupXml.ToString());
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/directory/");
                foreach (XmlNode group in doc.SelectNodes("//sp:Groups/sp:Group", nsmgr))
                {
                    groups.Add(group.Attributes["Name"].Value.ToUpper(), "");
                }
            }
            catch (Exception e)
            {
                error = "ERROR: " + e.Message;
                return groups;
            }

            return groups;
        }