执行IReportServerCredentials错误
我拿了示例代码来实现IReportServerCredentials以发送登录信息来远程检索报告,但出于某种原因实现容易出错。执行IReportServerCredentials错误
Imports System.Net
Imports Microsoft.Reporting.WebForms
Imports System.Security.Principal
<Serializable()> _
Public NotInheritable Class ReportServerNetworkCredentials
Implements IReportServerCredentials
#Region "IReportServerCredentials Members"
''' <summary>
''' Specifies the user to impersonate when connecting to a report server.
''' </summary>
''' <value></value>
''' <returns>A WindowsIdentity object representing the user to impersonate.</returns>
Public ReadOnly Property ImpersonationUser() As WindowsIdentity Implements IReportServerCredentials.ImpersonationUser
Get
Return Nothing
End Get
End Property
''' <summary>
''' Returns network credentials to be used for authentication with the report server.
''' </summary>
''' <value></value>
''' <returns>A NetworkCredentials object.</returns>
Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials Implements IReportServerCredentials.NetworkCredentials
Get
dim userName As String = _
ConfigurationManager.AppSettings("MyReportViewerUser")
If (String.IsNullOrEmpty(userName)) Then
Throw New Exception("Missing user name from web.config file")
End If
Dim password As String = _
ConfigurationManager.AppSettings("MyReportViewerPassword")
If (String.IsNullOrEmpty(password)) Then
Throw New Exception("Missing password from web.config file")
End If
Dim domain As String = _
ConfigurationManager.AppSettings("MyReportViewerDomain")
If (String.IsNullOrEmpty(domain)) Then
Throw New Exception("Missing domain from web.config file")
End If
Return New System.Net.NetworkCredential(userName, password, domain)
End Get
End Property
''' <summary>
''' Provides forms authentication to be used to connect to the report server.
''' </summary>
''' <param name="authCookie">A Report Server authentication cookie.</param>
''' <param name="userName">The name of the user.</param>
''' <param name="password">The password of the user.</param>
''' <param name="authority">The authority to use when authenticating the user, such as a Microsoft Windows domain.</param>
''' <returns></returns>
Public Function GetFormsCredentials(ByVal authCookie As System.Net.Cookie, ByVal userName As String, ByVal password As String, ByVal authority As String) As Boolean Implements IReportServerCredentials.GetFormsCredentials
authCookie = Nothing
userName = Nothing
password = Nothing
authority = Nothing
Return False
End Function
#END地区
类声明末级
存在对
Implements IReportServerCredentials
的错误行,它说的类必须实现功能getformscredentials ....对interface microsoft.reporting.webforms.ireportservercredentials ...
现在,当我相应地更改功能时,它仍然会给出相同的错误。
我假定这是完全错误消息:
“公职GetFormsCredentials(authCookie作为System.Net.Cookie,用户名作为字符串,密码作为字符串,权威作为字符串)作为布尔”和'Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie,ByRef userName As String,ByRef password As String,ByRef authority As String)由于布尔'不能互相重载,因为它们只有声明'ByRef'或'ByVal'的参数不同, 。
在IReportServerCredentials.GetFormsCredentials的MSDN文档的语法部分中,您会看到此声明的示例代码。
'Declaration
Function GetFormsCredentials (_
<OutAttribute> ByRef authCookie As Cookie, _
<OutAttribute> ByRef userName As String, _
<OutAttribute> ByRef password As String, _
<OutAttribute> ByRef authority As String _
) As Boolean
你的funciton声明缺少ByRef关键字和每个参数的OutAttribute。 ByRef属性告诉VB.NET编译器将参数值传回给调用者。 OutAttribute告诉编译器构建调用代码,在传递之前不需要初始化参数。您可以从MSDN上的Directional Attributes文章中找到有关out参数的更多信息,以及Lasse V. Karlsen在关于<Out()> attribute的*问题。
OutAttribute是在System.Runtime.InteropServices命名空间中声明的,因此您需要在您的文件顶部使用此Import语句。
Imports System.Runtime.InteropServices
你的函数应该看起来更像是这样的:
Public Function GetFormsCredentials(<OutAttribute()> ByRef authCookie As System.Net.Cookie, <OutAttribute()> ByRef userName As String, <OutAttribute()> ByRef password As String, <OutAttribute()> ByRef authority As String) As Boolean Implements IReportServerCredentials.GetFormsCredentials
authCookie = Nothing
userName = Nothing
password = Nothing
authority = Nothing
Return False
End Function