我正在尝试在.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对象,但无论哪种方式,结果都是以下错误:
消息安全性异常:HTTP请求未经授权,客户端身份验证方案为“Anonymous”。从服务器收到的身份验证标头为“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。有什么想法吗?
4条答案
按热度按时间ddarikpa1#
经过一天的努力,我找到了一种似乎可行的方法,即使用唯一一个不会立即调用ConfigureEndpoint的构造函数(如问题中所指出的)。如果我创建一个指定NTLM的绑定,并将该绑定与一个手动创建的端点沿着传递,则该方法可行:
这对我在.NET核心中是有效的。
ct2axkht2#
编辑:更新.NET Core的程式码
不幸的是,我现在没有SSRS来测试代码。
但是,请尝试以下代码(无错误检查):
mgdq6dx13#
^^^这适用于NTLM。
另外,我在客户端创建后尝试设置一些属性时遇到只读错误。为了帮助某些人,必须在创建客户端时设置所有属性,以避免出现上述“yourClient”所述的情况。
rkttyhzu4#
我遇到了同样的问题,对我来说,以下补充是有帮助的: