实现IReportServerCredentials错误

时间:2011-05-10 21:54:16

标签: vb.net sql-server-2008 reporting

我使用示例代码实现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 Region

结束班

在类声明上有

的错误行
 Implements IReportServerCredentials

它说类必须实现函数getformscredentials ....用于接口microsoft.reporting.webforms.ireportservercredentials ...

现在,当我相应地更改功能时,它仍然会出现相同的错误。

1 个答案:

答案 0 :(得分:1)

我假设这是完整的错误消息:

  

'Public Function GetFormsCredentials(authCookie As System.Net.Cookie,userName As String,password As String,authority As String)As Boolean'和'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文章以及Lasse V的这个有用响应中找到有关out参数的更多信息。关于<Out()> attribute的StackOverflow问题,Karlsen。

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