Esempio n. 1
0
        public static Resources Connect()
        {
            String[] appCon = new String[7];

            appCon[0] = GetAppSetting("ServiceUri");
            appCon[1] = GetAppSetting("UserName");
            appCon[2] = GetAppSetting("Password");
            appCon[3] = GetAppSetting("ActiveDirectoryResource");
            appCon[4] = GetAppSetting("ActiveDirectoryTenant");
            appCon[5] = GetAppSetting("ActiveDirectoryClientAppId");
            appCon[6] = GetAppSetting("ActiveDirectoryClientAppSecret");


            string ODataEntityPath = appCon[0] + "data";
            Uri    oDataUri        = new Uri(ODataEntityPath, UriKind.Absolute);

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            var context = new Resources(oDataUri);

            context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e)
            {
                var authenticationHeader = OAuthHelper.GetAuthenticationHeader2(true, appCon);
                e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader);
            });

            return(context);
        }