private ValidatedResponse<CatalogItem> GetReportObjectFromSSRS(string reportName) { CatalogItem catalogItem; var client = new ReportingService2010SoapClient(); try { // Get EndPoint Address from AppSettings. Log.Information("GetReportObjectFromSSRS : Getting the report object {@reportName}", reportName); var trustedUserHeader = new RS2010.TrustedUserHeader(); client.Endpoint.Address = this.reportService2010Reference; client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; client.ClientCredentials.Windows.ClientCredential = null; client.Open(); Log.Information("GetReportObjectFromSSRS : Reporting Service 2010 Soap Client Uri - {@uri}", this.reportService2010Reference.Uri); //// I need to list of children of a specified folder. CatalogItem[] items; client.ListChildren(trustedUserHeader, "/", true, out items); catalogItem = (from CatalogItem ci in items where ci.TypeName.Contains("Report") && ci.Name.Equals(reportName, StringComparison.OrdinalIgnoreCase) select ci).FirstOrDefault(); Log.Information("GetReportObjectFromSSRS : Catalog Item {@catalogItem} was successfully obtained", catalogItem.Name); Log.Information("GetReportObjectFromSSRS : Successfully obtained Report Object"); return ValidatedResponse<CatalogItem>.Success(catalogItem); } catch (Exception ex) { Log.Error(ex, "GetReportObjectFromSSRS: Something went wrong in getting the SSRS Report Object - {@reportname}", reportName); return ValidatedResponseHelper.Failure<CatalogItem>("Error {0}", ex.ToString()); } finally { client.Close(); } }
private void test_1() { NetworkCredential clientCredentials = new NetworkCredential("Chathuranga", "blahhhhh", "Chathu-Nable"); ReportingService2010SoapClient client = new ReportingService2010SoapClient(); client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; client.ClientCredentials.Windows.ClientCredential = clientCredentials; client.Open(); TrustedUserHeader t = new TrustedUserHeader(); CatalogItem[] items; // I need to list of children of a specified folder. ServerInfoHeader oServerInfoHeader = client.ListChildren(t, "/", true, out items); foreach (var item in items) { // I can access any properties of item Console.WriteLine(item.ID); } Console.ReadLine(); }
private void UploadReportDataSources(ReportingService2010SoapClient reportingServicesClient, TrustedUserHeader userHeader, string artifactsFolderPath) { foreach (var dataSourceDefinitionFile in Directory.GetFiles(artifactsFolderPath, String.Format("*{0}", DataSourceFileExtension))) { string itemName = Path.GetFileNameWithoutExtension(dataSourceDefinitionFile); CatalogItem dataSetItem = null; DataSourceDefinition definition = DataSourceDefinitionParser.Parse(File.OpenRead(dataSourceDefinitionFile)); Console.WriteLine("Uploaded report data source '{0}'", itemName); reportingServicesClient.CreateDataSource(userHeader, itemName, "/", true, definition, null, out dataSetItem); } }
public void Dispose() { try { WcfHelpers.CleanUpQuietly(service); } finally { service = null; } }
public void Upload(string targetServerUri, string artifactsFolderPath) { bool isHttpsEndpoint = new Uri(targetServerUri).Scheme == Uri.UriSchemeHttps; ReportingService2010SoapClient reportingServicesClient = CreateClientProxy(targetServerUri, isHttpsEndpoint); var userHeader = new TrustedUserHeader(); UploadReportDataSources(reportingServicesClient, userHeader, artifactsFolderPath); UploadSharedDataSets(reportingServicesClient, userHeader, artifactsFolderPath); UploadReports(reportingServicesClient, userHeader, artifactsFolderPath); }
public CatalogItem[] ListReportCollection(string itemPath, bool recursive) { CatalogItem[] reportCollection = { }; try { ReportingService2010SoapClient client = new ReportingService2010SoapClient(); //NT LAN Manager (NTLM) is a suite of Microsoft security protocols that provides authentication, integrity, and confidentiality to users.[1][2][3] NTLM is the successor to the authentication protocol in Microsoft LAN Manager (LANMAN), client.ClientCredentials.Windows.AllowNtlm = true; client.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; // // Summary: // The server process can impersonate the client's security context on its local // system. The server cannot impersonate the client on remote systems. // Impersonation = 3, // Finally figure it out. // My Reporting Services were configured to a local account while my Application Pool for IIS was configured to ApplicationPoolIdentity. // I changed my Application Pool to LocalSystem and it fixed it. Hopefully this information will be useful to others as I wasted several hours figuring this out. client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; CatalogItem aCatalogItem = new CatalogItem(); // aCatalogItem.TypeName // Summary: // The server process can impersonate the client's security context on remote // systems. // client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; client.Open(); TrustedUserHeader t = new TrustedUserHeader(); try { // I need to list of children of a specified folder. client.ListChildren(t, itemPath, recursive, out reportCollection); // see http://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010.listchildren.aspx } catch (SoapException ex) { // _logger.Error("ReportServerManagementService--" + ex); } } catch (SoapException ex) { // _logger.Error("ReportServerManagementService--" + ex); } return(reportCollection); }
private void UploadSharedDataSets(ReportingService2010SoapClient reportingServicesClient, TrustedUserHeader userHeader, string artifactsFolderPath) { foreach (var dataSetDefinitionFile in Directory.GetFiles(artifactsFolderPath, String.Format("*{0}", DataSetFileExtension))) { string itemName = Path.GetFileNameWithoutExtension(dataSetDefinitionFile); byte[] itemDefinition = File.ReadAllBytes(dataSetDefinitionFile); CatalogItem dataSetItem = null; Warning[] warnings = null; Console.WriteLine("Uploaded shared data set '{0}'", itemName); reportingServicesClient.CreateCatalogItem(userHeader, "DataSet", itemName, "/", true, itemDefinition, null, out dataSetItem, out warnings); } }
private SSRSServiceHandler() { NetworkCredential clientCredentials = new NetworkCredential("Test", "123", "Chathu-Nable"); serviceClient = new ReportingService2010SoapClient(); serviceClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; serviceClient.ClientCredentials.Windows.ClientCredential = clientCredentials; serviceClient.Open(); userHeader = new TrustedUserHeader(); }
private void UploadReports(ReportingService2010SoapClient reportingServicesClient, TrustedUserHeader userHeader, string artifactsFolderPath) { foreach (var reportDefinitionFile in Directory.GetFiles(artifactsFolderPath, String.Format("*{0}", ReportFileExtension))) { string itemName = Path.GetFileNameWithoutExtension(reportDefinitionFile); byte[] itemDefinition = File.ReadAllBytes(reportDefinitionFile); CatalogItem dataSetItem = null; Warning[] warnings = null; Console.WriteLine("Uploaded report '{0}'", itemName); reportingServicesClient.CreateCatalogItem(userHeader, "Report", itemName, "/", true, itemDefinition, null, out dataSetItem, out warnings); } }
private void DownloadReports(ReportingService2010SoapClient reportingServicesClient, TrustedUserHeader userHeader, CatalogItem[] items) { foreach (var reportDefinition in items.Where(item => item.TypeName == "Report")) { byte[] itemDefinition = null; reportingServicesClient.GetItemDefinition(userHeader, reportDefinition.Path, out itemDefinition); string reportContents = new StreamReader(new MemoryStream(itemDefinition)).ReadToEnd(); string outputFilePath = Path.Combine(outputFolderPath, reportDefinition.Name + ReportFileExtension); Console.WriteLine("Downloaded report '{0}' into file '{1}'", reportDefinition.Name, outputFilePath); File.WriteAllText(outputFilePath, reportContents); } }
private void DownloadSharedDataSets(ReportingService2010SoapClient reportingServicesClient, TrustedUserHeader userHeader, CatalogItem[] items) { foreach (var dataSetDefinition in items.Where(item => item.TypeName == "DataSet")) { byte[] itemDefinition = null; string outputFilePath = Path.Combine(outputFolderPath, dataSetDefinition.Name + DataSetFileExtension); reportingServicesClient.GetItemDefinition(userHeader, dataSetDefinition.Path, out itemDefinition); string reportContents = new StreamReader(new MemoryStream(itemDefinition)).ReadToEnd(); Console.WriteLine("Downloaded shared data set '{0}' into file '{1}'", dataSetDefinition.Name, outputFilePath); File.WriteAllText(outputFilePath, reportContents); } }
public void Download(string targetServerUri, string artifactsFolderPath) { bool isHttpsEndpoint = new Uri(targetServerUri).Scheme == Uri.UriSchemeHttps; outputFolderPath = artifactsFolderPath; ReportingService2010SoapClient reportingServicesClient = CreateClientProxy(targetServerUri, isHttpsEndpoint); var userHeader = new TrustedUserHeader(); CatalogItem[] items = null; reportingServicesClient.ListChildren(userHeader, "/", true, out items); DownloadReportDataSources(reportingServicesClient, userHeader, items); DownloadSharedDataSets(reportingServicesClient, userHeader, items); DownloadReports(reportingServicesClient, userHeader, items); }
public ReportingServiceClient(Uri ssrsUri) { var binding = GetBinding(ssrsUri); binding.SendTimeout = Timeout; binding.OpenTimeout = Timeout; if (binding.ReceiveTimeout < Timeout) { binding.ReceiveTimeout = Timeout; } var endpointAddress = new EndpointAddress(ssrsUri); service = new ReportingService2010SoapClient(binding, endpointAddress); Debug.Assert(service.ClientCredentials != null); service.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; service.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; }
public MsReportingServices(string reportingServicesUrl, string networkDomain, string networkLogin, string networkPassword) { Log("Creating MsReportingServices instance"); if (!Uri.TryCreate(reportingServicesUrl, UriKind.RelativeOrAbsolute, out Uri reportingServicesUri)) { throw new UriFormatException($"reporting services uri of '{reportingServicesUri}' is invalid!"); } if (string.IsNullOrWhiteSpace(networkPassword)) { throw new NullReferenceException("networkPassword is null or empty!"); } if (string.IsNullOrWhiteSpace(networkDomain)) { throw new NullReferenceException("networkDomain is null or empty!"); } if (string.IsNullOrWhiteSpace(networkLogin)) { throw new NullReferenceException("networkLogin is null or empty!"); } var binding = new BasicHttpBinding { Name = "bindingReportingServices2010", Security = new BasicHttpSecurity { Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.Ntlm }, Mode = BasicHttpSecurityMode.TransportCredentialOnly }, MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue, MaxBufferPoolSize = int.MaxValue }; var endpoint = new EndpointAddress(reportingServicesUri); reportingServicesClient = new ReportingService2010SoapClient(binding, endpoint); reportingServicesClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; reportingServicesClient.ClientCredentials.Windows.ClientCredential = new NetworkCredential(networkLogin, networkPassword, networkDomain); }
/// <summary> /// Tests the connection. /// </summary> /// <param name="message">The message.</param> /// <param name="type">The type.</param> /// <returns></returns> public bool TestConnection(out string message, UserType type) { bool isSuccessful = false; message = string.Empty; try { ReportingService2010SoapClient client = GetClient(UserType.ContentManager); Property[] userProperties = null; if (TestPath()) { message = "Succesfully connected."; isSuccessful = true; } else { message = "Connection Error"; } } catch (Exception ex) { bool caught = false; if (ex.InnerException != null && ex.InnerException.GetType() == typeof(System.Net.WebException)) { System.Net.WebException webEx = (System.Net.WebException)ex.InnerException; if (((System.Net.HttpWebResponse)webEx.Response).StatusCode == System.Net.HttpStatusCode.Unauthorized) { message = "User is not authorized."; caught = true; } } if (!caught) { message = string.Format("An error has occurred when Loading Reporting Services. {0}", ex.Message); } isSuccessful = false; } return(isSuccessful); }
protected ReportingService2010SoapClient CreateClientProxy(string targetServerUri, bool isHttpsEndpoint) { Binding secureBinding = new BasicHttpBinding() { Security = new BasicHttpSecurity() { Mode = isHttpsEndpoint ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.TransportCredentialOnly, Transport = new HttpTransportSecurity() { ClientCredentialType = HttpClientCredentialType.Ntlm, ProxyCredentialType = HttpProxyCredentialType.Ntlm }, Message = new BasicHttpMessageSecurity() { AlgorithmSuite = SecurityAlgorithmSuite.Default, ClientCredentialType = BasicHttpMessageCredentialType.UserName } }, ReaderQuotas = new XmlDictionaryReaderQuotas() { MaxDepth = int.MaxValue, MaxArrayLength = int.MaxValue, MaxBytesPerRead = 4096, MaxNameTableCharCount = int.MaxValue, MaxStringContentLength = int.MaxValue }, MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue }; EndpointAddress endpointAddress = new EndpointAddress(targetServerUri); ReportingService2010SoapClient reportingServicesClient = new ReportingService2010SoapClient(secureBinding, endpointAddress); reportingServicesClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; reportingServicesClient.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; return(reportingServicesClient); }
/// <summary> /// Initializes a new instance of ReportServices to retrieve reports, /// to download and upload reports, etc. /// </summary> /// <param name="reportServerUrl"></param> /// <param name="login"></param> /// <param name="password"></param> /// <param name="domain"></param> public ReportServices(string reportServerUrl, string login, string password, string domain) { string url = reportServerUrl; if (!url.EndsWith("/") && !url.EndsWith(".asmx")) { url += "/ReportService2010.asmx"; } else if (!url.EndsWith(".asmx")) { url += "ReportService2010.asmx"; } NetworkCredential user = String.IsNullOrEmpty(domain) ? new NetworkCredential(login, password) : new NetworkCredential(login, password, domain); var binding = new System.ServiceModel.BasicHttpBinding(); binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Ntlm; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Message.ClientCredentialType = System.ServiceModel.BasicHttpMessageCredentialType.UserName; binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default; binding.MaxReceivedMessageSize = 65536999; binding.MaxBufferSize = 65536999; binding.SendTimeout = new TimeSpan(0, 0, 0, 20); binding.OpenTimeout = new TimeSpan(0, 0, 0, 20); binding.ReaderQuotas.MaxStringContentLength = 10000; binding.ReaderQuotas.MaxDepth = 10000; binding.ReaderQuotas.MaxArrayLength = 10000; var endpoint = new System.ServiceModel.EndpointAddress(url); _service = new ReportingService2010SoapClient(binding, endpoint); _service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; _service.ClientCredentials.Windows.ClientCredential = user; _service.Open(); }
protected ReportingService2010SoapClient CreateClientProxy(string targetServerUri, bool isHttpsEndpoint) { Binding secureBinding = new BasicHttpBinding() { Security = new BasicHttpSecurity() { Mode = isHttpsEndpoint ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.TransportCredentialOnly, Transport = new HttpTransportSecurity() { ClientCredentialType = HttpClientCredentialType.Ntlm, ProxyCredentialType = HttpProxyCredentialType.Ntlm }, Message = new BasicHttpMessageSecurity() { AlgorithmSuite = SecurityAlgorithmSuite.Default, ClientCredentialType = BasicHttpMessageCredentialType.UserName } }, ReaderQuotas = new XmlDictionaryReaderQuotas() { MaxDepth = int.MaxValue, MaxArrayLength = int.MaxValue, MaxBytesPerRead = 4096, MaxNameTableCharCount = int.MaxValue, MaxStringContentLength = int.MaxValue }, MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue }; EndpointAddress endpointAddress = new EndpointAddress(targetServerUri); ReportingService2010SoapClient reportingServicesClient = new ReportingService2010SoapClient(secureBinding, endpointAddress); reportingServicesClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; reportingServicesClient.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; return reportingServicesClient; }
/// <summary> /// Gets the client. /// </summary> /// <param name="ut">The ut.</param> /// <returns></returns> private ReportingService2010SoapClient GetClient(UserType ut) { if (rsClient != null && ut == rsUserType) { return(rsClient); } else { rsClient = null; } var binding = new BasicHttpBinding(); binding.Name = "ReportingServicesBinding"; binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm; binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; binding.Security.Transport.Realm = ""; binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default; string url = string.Format("{0}/ReportService2010.asmx", ServerUrl); var endpoint = new EndpointAddress(url); rsClient = new ReportingService2010SoapClient(binding, endpoint); rsClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; if (ut == UserType.ContentManager) { rsClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(ContentManagerUser, ContentManagerPassword); } else { rsClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(BrowserUser, BrowserPassword); } rsUserType = ut; return(rsClient); }
private void grantPriviledges_2() { NetworkCredential clientCredentials = new NetworkCredential("Test", "123", "Chathu-Nable"); ReportingService2010SoapClient client = new ReportingService2010SoapClient(); client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; client.ClientCredentials.Windows.ClientCredential = clientCredentials; client.Open(); TrustedUserHeader t = new TrustedUserHeader(); Policy [] arrPolicies = null; bool doesInheritParent = false; client.GetPolicies(t, "/New Folder", out arrPolicies, out doesInheritParent); List <Policy> listPolicies = new List <Policy>(); if (arrPolicies != null) { listPolicies = arrPolicies.ToList(); } listPolicies.Add( new Policy() { Roles = new[] { new Role() { Name = "Browser" }, new Role() { Name = "Content Manager" } }, GroupUserName = "******" } ); client.SetPolicies(t, "/New Folder", listPolicies.ToArray()); /* * * Policy[] MyPolicyArr = new Policy[2]; * * * Role[] MyRoles = new Role[3]; * * Role browser = new Role(); * browser.Name = "Browser"; * * Role myReports = new Role(); * myReports.Name = "My Reports"; * * Role publisher = new Role(); * publisher.Name = "Publisher"; * * Role contentManager = new Role() { Name = "Content Manager" }; * * MyRoles[0] = publisher; * MyRoles[1] = browser; * MyRoles[2] = contentManager; * * * MyPolicyArr[0] = new Policy() { GroupUserName = @"Chathu-Nable\Test", Roles = MyRoles }; * MyPolicyArr[1] = new Policy() { GroupUserName = @"Chathu-Nable\Test2", Roles = MyRoles }; * * * client.SetPolicies(t, "/New Folder", MyPolicyArr); * * //rs.SetPolicies("/SecurityTestFolder", MyPolicyArr); * */ //MessageBox.Show(policies.Length + "") ; }
public ReportServerExecutionContext(ReportingService2010SoapClient client) { this.Client = client; }
private void grantPriviledges_1() { NetworkCredential clientCredentials = new NetworkCredential("Test", "123", "Chathu-Nable"); ReportingService2010SoapClient client = new ReportingService2010SoapClient(); client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; client.ClientCredentials.Windows.ClientCredential = clientCredentials; client.Open(); TrustedUserHeader t = new TrustedUserHeader(); Policy[] MyPolicyArr = new Policy[2]; Role[] MyRoles = new Role[3]; Role browser = new Role(); browser.Name = "Browser"; Role myReports = new Role(); myReports.Name = "My Reports"; Role publisher = new Role(); publisher.Name = "Publisher"; Role contentManager = new Role() { Name = "Content Manager" }; MyRoles[0] = publisher; MyRoles[1] = browser; MyRoles[2] = contentManager; MyPolicyArr[0] = new Policy() { GroupUserName = @"Chathu-Nable\Test", Roles = MyRoles }; MyPolicyArr[1] = new Policy() { GroupUserName = @"Chathu-Nable\Test2", Roles = MyRoles }; client.SetPolicies(t, "/New Folder", MyPolicyArr); //rs.SetPolicies("/SecurityTestFolder", MyPolicyArr); MessageBox.Show("blahhhh"); }
private void StartUpSSRS() { try { clientSoap = new ReportingService2010SoapClient(); clientSoap.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(USER_DS, PASSWORD_DS); clientSoap.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; /*TrustedUserHeader Myheader = new TrustedUserHeader(); string reportName = "/CMD/AccountPenetrationReport"; byte[] reportDefinition = null; clientSoap.GetItemDefinition(Myheader, reportName, out reportDefinition);*/ } catch (SoapException e) { Console.WriteLine(e.Detail.InnerXml.ToString()); } catch (Exception e) { Debug.WriteLine(e.ToString()); } }