实施 IReportServerCredentials 错误

发布于 2024-11-06 11:11:54 字数 3107 浏览 0 评论 0原文

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

End Class

类声明上有一个错误行

 Implements IReportServerCredentials

,它表示类必须实现函数 getformscredentials....for 接口 microsoft.reporting.webforms.ireportservercredentials...

现在,当我相应地更改函数时,它仍然给出同样的错误。

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, 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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两仪 2024-11-13 11:11:55

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

“公共函数 GetFormsCredentials(authCookie As System.Net.Cookie, userName As String,password As String,authority As String) As Boolean”和“公共函数 GetFormsCredentials(ByRef authCookie As System.Net.Cookie, ByRef userName As String) 、ByRef 密码作为字符串、ByRef 权限作为字符串) As Boolean' 不能互相重载,因为它们仅在声明为 'ByRef' 或 'ByVal' 的参数上有所不同。

在 MSDN 文档的语法部分中 IReportServerCredentials.GetFormsCredentials 您会看到声明的示例代码。

'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

您的函数声明缺少 ByRef 关键字和每个参数的 OutAttribute。 ByRef 属性告诉 VB.NET 编译器将参数的值传递回调用者。 OutAttribute 告诉编译器构建调用代码,它不需要在传入参数之前初始化参数。您可以从 Directional Attributes MSDN 上的文章以及 Lasse V. Karlsen 关于 StackOverflow 关于 属性

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文