Bra*_*don 5 c# web-services reporting-services .net-core
我正在尝试在 .NET Core 中执行 SSRS 报告。
由于 .NET Core 不允许您添加服务引用,因此您必须使用 WCF Connected Service 添加对 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")
}
}
};
Run Code Online (Sandbox Code Playgroud)
还尝试设置 Username 对象而不是 Windows 对象,但无论哪种方式,结果都是以下错误:
MessageSecurityException:HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是“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);
Run Code Online (Sandbox Code Playgroud)
我可能弄错了,但这不是在设置 ClientCredentials 对象之前使用 ClientCredentials 对象调用私有方法 ConfigureEndpoint 吗?
我没有看到任何其他方式来配置 ClientCredentials 或调用 ConfigureEndpoint,那么您究竟应该如何进行身份验证?其他构造函数基本相同,除了一个接受 Binding 而不是 EndpointConfiguration 的构造函数。有任何想法吗?
编辑:更新.NET Core的代码
不幸的是,我现在没有 SSRS 来测试代码。
但是,尝试这个代码(没有错误检查):
// parameters of report (if any)
ParameterValue[] parameters = {new ParameterValue {Name = "ApontamentoID", Value = "364"}};
// connect to the service
ReportExecutionServiceSoapClient webServiceProxy =
new ReportExecutionServiceSoapClient(
ReportExecutionServiceSoapClient.EndpointConfiguration.ReportExecutionServiceSoap,
"http://report_server_url/ReportExecution2005.asmx?wsdl");
// logon the user
await webServiceProxy.LogonUserAsync("username", "password", null);
// ask for the report
await webServiceProxy.LoadReportAsync("/report_path", null);
await webServiceProxy.SetExecutionParametersAsync(parameters, null);
// you can use RenderStreamRequest too
RenderRequest request = new RenderRequest("pdf", null);
RenderResponse response = await webServiceProxy.RenderAsync(request);
// save to the disk
System.IO.File.WriteAllBytes(@"c:\temp\output.pdf", response.Result);
// logoff the user
await webServiceProxy.LogoffAsync();
// close
await webServiceProxy.CloseAsync();
Run Code Online (Sandbox Code Playgroud)