wcf - .Net Core ReportExecutionServiceSoapClient 设置凭据

标签 wcf authentication soap reporting-services asp.net-core

我在 .Net Core 中使用 ReportExecutionServiceSoapClient 我获得了最新版本的 .net Core 并试图从报告服务中获取报告以使其工作。在使用 WCF 连接服务后,我可以添加如下所示的代码

        // Instantiate the Soap client
        ReportExecutionServiceSoap rsExec = new ReportExecutionServiceSoapClient(ReportExecutionServiceSoapClient.EndpointConfiguration.ReportExecutionServiceSoap);
        // Create a network credential object with the appropriate username and password used
        // to access the SSRS web service
        string historyID = null;
        TrustedUserHeader trustedUserHeader = new TrustedUserHeader();
        ExecutionHeader execHeader = new ExecutionHeader();

        // Here we call the async LoadReport() method using the "await" keyword, which means any code below this method
        // will not execute until the result from the LoadReportAsync task is returned

        var taskLoadReport = rsExec.LoadReportAsync(reportPath, historyID);
        // By the time the LoadReportAsync task is returned successfully, its "executionInfo" property
        // would have already been populated. Now the remaining code in this main thread will resume executing

        string deviceInfo = null;
        string format = "EXCEL";
        // Now, similar to the above task, we will call the RenderAsync() method and await its result
        var taskRender = await rsExec.RenderAsync(renderReq);

当它出现 renderAsync 时,所有的都崩溃了,因为服务的凭据没有在任何地方设置。我试图登录异步但没有成功。此外,我尝试使用 SetExecutionCredentialsAsync 设置凭据,但出现错误提示“HTTP 请求未经客户端身份验证方案‘匿名’授权。从服务器收到的身份验证 header 为‘NTLM’。”我不知道如何为 ReportExecutionServiceSoapClient 更改它。

我读过一些帖子,其中微软的人说使用 SOAP 的身份验证没有解决,但对我来说,这似乎是真的。我觉得我错过了一些东西。

技术栈:VS 2017、.net Core web api、ssrs 2016、sql server 2016标准

如何验证此调用的用户身份?

最佳答案

我知道这是一个老问题,但我遇到了同样的问题并偶然发现了答案。

创建 ReportExecutionServiceSoap 对象后,您可以在 ClientCredentials 中指定用户名和密码。我使用 Basic 客户端凭据类型在此方面取得了成功。请确保您使用的是 HTTPS,否则您的密码将以明文形式发送到报告服务器。我还建议将用户/密码存储在安全的地方而不是代码。

BasicHttpBinding rsBinding = new BasicHttpBinding();
rsBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
rsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

EndpointAddress rsEndpointAddress = new EndpointAddress("https://servername/ReportServer/ReportExecution2005.asmx");

var rsExec = new ReportExecutionServiceSoapClient(rsBinding, rsEndpointAddress);
rsExec.ClientCredentials.UserName.UserName = "username";
rsExec.ClientCredentials.UserName.Password = "pass";

关于wcf - .Net Core ReportExecutionServiceSoapClient 设置凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43210261/

相关文章:

SOAP UI 变量(例如,日期)

wcf - WF 4 中与工作流 InstanceId 的相关性

java - java中的json从列表中获取正确的值

asp.net - asp.net 中的身份验证 Cookie

web-services - 使用 SoapUI 和 Windows 身份验证测试 Web 服务

php - 糖皂 set_entry

c# - WCF 服务不是多线程的

wcf - 添加用于 WCF 服务和 Windows Phone 7 应用程序的枚举类型

android - 如何在android中检查设备兼容性以进行指纹认证

authentication - 为什么我的 cookie 身份验证在 asp .net core 中不起作用?