开发者

Implement IReportServerCredentials error

I took sample code to implement the IReportServerCredentials to send the login information to retrieve a report remotely but for some reason the implementation is error prone.

 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, ByV开发者_如何学Goal 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

End Class

on the class declaration there is an error line for

 Implements IReportServerCredentials

and it says class must implement function getformscredentials....for interface microsoft.reporting.webforms.ireportservercredentials...

Now when I change the function accordingly it still gives the same error.


I am assuming that this is the full error message:

'Public Function GetFormsCredentials(authCookie As System.Net.Cookie, userName As String, password As String, authority As String) As Boolean' and 'Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean' cannot overload each other because they differ only by parameters declared 'ByRef' or 'ByVal'.

In the Syntax section of the MSDN docs for IReportServerCredentials.GetFormsCredentials you see this sample code for the declaration.

'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

Your funciton declaration is missing the ByRef keyword and the OutAttribute on each parameter. The ByRef attribute tells the VB.NET compiler to pass the parameter's value back out to the caller. The OutAttribute tells the compiler building the calling code that it does not need to initialize the parameter before passing it in. You can find more information about out parameters from the Directional Attributes article on MSDN as well as this helpful response from Lasse V. Karlsen on a StackOverflow question about the <Out()> attribute.

The OutAttribute is declared in the System.Runtime.InteropServices namespace, so you will need this Import statement at the top of your file.

Imports System.Runtime.InteropServices

Your function should look more like this:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜