我正在尝试在.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")
}
}
};
还尝试设置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);
我可能弄错了,但是在调用ClientCredentials对象之前,这不是用ClientCredentials对象调用私有方法ConfigureEndpoint吗?
我没有看到任何其他方法来配置ClientCredentials或调用ConfigureEndpoint,那么您应该如何进行身份验证呢?其他构造函数基本上是相同的,除了一个接受Binding而不是EndpointConfiguration的构造函数。有什么想法吗?
答案 0 :(得分:1)
经过一天的努力,我发现了一种似乎可行的方法,方法是使用唯一的构造器,该构造器不会立即调用问题中指出的ConfigureEndpoint。如果我创建一个指定NTLM的绑定,并将该绑定与手动创建的端点一起传递,则它将起作用:
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中对我有用。
答案 1 :(得分:0)
编辑:更新.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();