c# - 在 .NET Core 中针对 ReportExecution2005.asmx 进行身份验证

标签 c# web-services reporting-services .net-core

我正在尝试在 .NET Core 中执行 SSRS 报告。

由于 .NET Core 不允许您添加服务引用,您必须使用 WCF 连接服务添加对 WSDL 的引用,以便它可以生成 .NET Core 兼容代码。这就是我为 ReportExecution2005.asmx(如果重要的话,SQL Server 2016)所做的。

我尝试使用以下方法对服务进行身份验证:

var rsExec = new ReportExecutionServiceSoapClient(ReportExecutionServiceSoapClient.EndpointConfiguration.ReportExecutionServiceSoap,
                                                  new EndpointAddress("http://server/ReportServer/ReportExecution2005.asmx"))
                    {
                        ClientCredentials =
                        {
                            Windows =
                            {
                                AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation,
                                ClientCredential = new NetworkCredential("username", "password")
                            }
                        }
                    };

还尝试设置用户名对象而不是 Windows 对象,但无论哪种方式,结果都是以下错误:

MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.

看看 Fiddler,代码没有传递凭据。

这是从 WSDL 生成的代码

public ReportExecutionServiceSoapClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress)
   : base(ReportExecutionServiceSoapClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
{
    this.Endpoint.Name = endpointConfiguration.ToString();
    ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);

我可能弄错了,但这不是在 ClientCredentials 对象还未设置之前就用 ClientCredentials 对象调用了私有(private)方法 ConfigureEndpoint 吗?

我没有看到配置 ClientCredentials 或调用 ConfigureEndpoint 的任何其他方式,那么您究竟应该如何进行身份验证?其他构造函数基本上是相同的,除了一个接受 Binding 而不是 EndpointConfiguration 的构造函数。有什么想法吗?

最佳答案

与此斗争了一天之后,我发现了一种似乎有效的方法,即使用问题中指出的唯一不会立即调用 ConfigureEndpoint 的构造函数。如果我创建一个指定 NTLM 的绑定(bind),并将该绑定(bind)与手动创建的端点一起传递,它会起作用:

var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly)
{
    Security =
    {
        Transport = new HttpTransportSecurity {ClientCredentialType = HttpClientCredentialType.Ntlm}
    }
};

var reportService = new CssbiReportService.ReportExecutionServiceSoapClient(binding,
    new EndpointAddress("http://myserver/ReportServer/ReportExecution2005.asmx"));

这在 .NET Core 中对我有用。

关于c# - 在 .NET Core 中针对 ReportExecution2005.asmx 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41942742/

相关文章:

c# - 用 C# 等效项替换由 CreateDispatch 调用调用的 VB6 DLL

java - WS 安全错误 : 181001 while trying to access to a web service through Apache CXF

android - 每 x 分钟通过 android 设备将更新的 GPS 坐标自动发送到 Web 服务器

c# - 从 SQL Server 获取列名

reporting-services - SSRS 格式编号错误

c# - 如何从 FileStream 报告进度

c# - ASP.NET Core - 无法在 Controller 内使用 C# StreamReader 读取静态 HTML 文件

c# - 使用 C#、Ajax、Jquery 的 Web 服务不适用于 ASP.Net

azure - Azure 虚拟机中托管的 SSRS 报告在 VM 外部不可用

asp.net - 报告服务 2008 - 401 : Unauthorized