如何忽略WebService请求中的SSL证书错误?

发布于 2024-09-24 15:22:17 字数 2161 浏览 4 评论 0原文

问:我编写了一个控制台程序,它使用 SQL Server 2005 Web 服务将报告上传到 SQL Server 2005 报告服务(这样我就不必每次都手动上传 100 个报告)。

它在本地和远程都运行良好。 但现在的问题是一台服务器使用 SSL 所以 rs.Url = "https://hostname/ReportServer/reportservice2005.asmx

现在的问题是 SSL 证书无效... 但是,我可以通过忽略此错误从浏览器访问报告服务器。 我怎样才能用网络服务做到这一点?

 ' http://msdn.microsoft.com/en-us/library/aa225813(SQL.80).aspx
    ' COR.Reporting.ReportingServiceInterface.CreateThisReport(strFileNameAndPath, strReportName, strReportingPath)
    ' COR.Reporting.ReportingServiceInterface.CreateThisReport("c:\path\to\file\xy.rdl", "xy", "/COR")
    Public Shared Sub CreateThisReport(ByVal strFileNameAndPath As String, ByVal strReportName As String, ByVal strReportingPath As String, Optional ByVal bOverwrite As Boolean = True)
        Dim rs As ReportingService2005 = New ReportingService2005
        rs.Credentials = ReportingServiceInterface.GetMyCredentials(strCredentialsURL)
        rs.Timeout = ReportingServiceInterface.iTimeout
        rs.Url = ReportingServiceInterface.strReportingServiceURL


        Dim btBuffer As Byte() = Nothing

        Dim rsWarnings As Warning() = Nothing
        Try
            Dim fstrStream As System.IO.FileStream = System.IO.File.OpenRead(strFileNameAndPath)
            btBuffer = New [Byte](fstrStream.Length) {}
            fstrStream.Read(btBuffer, 0, CInt(fstrStream.Length))
            fstrStream.Close()
        Catch ex As System.IO.IOException
            Throw New Exception(ex.Message)
        End Try


        Try
            rsWarnings = rs.CreateReport(strReportName, strReportingPath, bOverwrite, btBuffer, Nothing)

            If Not (rsWarnings Is Nothing) Then
                Dim warning As Warning
                For Each warning In rsWarnings
                    Console.WriteLine(warning.Message)
                Next warning
            Else
                Console.WriteLine("Report: {0} created successfully with no warnings", strReportName)
            End If

        Catch ex As System.Web.Services.Protocols.SoapException
            Console.WriteLine(ex.Detail.InnerXml.ToString())
        End Try
    End Sub ' End Function CreateThisReport

Question: I have written a console program that uses the SQL server 2005 web service to upload reports to SQL Server 2005 reporting service (so that I don't have to upload 100 reports by hand everytime).

It works fine locally, and remotely.
But now, the problem is one server uses SSL
so rs.Url = "https://hostname/ReportServer/reportservice2005.asmx

the problem now is the SSL certificate is invalid...
I can access the reportserver from the browser however by ignoring this error.
How can I do that with the webservice?

 ' http://msdn.microsoft.com/en-us/library/aa225813(SQL.80).aspx
    ' COR.Reporting.ReportingServiceInterface.CreateThisReport(strFileNameAndPath, strReportName, strReportingPath)
    ' COR.Reporting.ReportingServiceInterface.CreateThisReport("c:\path\to\file\xy.rdl", "xy", "/COR")
    Public Shared Sub CreateThisReport(ByVal strFileNameAndPath As String, ByVal strReportName As String, ByVal strReportingPath As String, Optional ByVal bOverwrite As Boolean = True)
        Dim rs As ReportingService2005 = New ReportingService2005
        rs.Credentials = ReportingServiceInterface.GetMyCredentials(strCredentialsURL)
        rs.Timeout = ReportingServiceInterface.iTimeout
        rs.Url = ReportingServiceInterface.strReportingServiceURL


        Dim btBuffer As Byte() = Nothing

        Dim rsWarnings As Warning() = Nothing
        Try
            Dim fstrStream As System.IO.FileStream = System.IO.File.OpenRead(strFileNameAndPath)
            btBuffer = New [Byte](fstrStream.Length) {}
            fstrStream.Read(btBuffer, 0, CInt(fstrStream.Length))
            fstrStream.Close()
        Catch ex As System.IO.IOException
            Throw New Exception(ex.Message)
        End Try


        Try
            rsWarnings = rs.CreateReport(strReportName, strReportingPath, bOverwrite, btBuffer, Nothing)

            If Not (rsWarnings Is Nothing) Then
                Dim warning As Warning
                For Each warning In rsWarnings
                    Console.WriteLine(warning.Message)
                Next warning
            Else
                Console.WriteLine("Report: {0} created successfully with no warnings", strReportName)
            End If

        Catch ex As System.Web.Services.Protocols.SoapException
            Console.WriteLine(ex.Detail.InnerXml.ToString())
        End Try
    End Sub ' End Function CreateThisReport

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

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

发布评论

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

评论(1

情绪少女 2024-10-01 15:22:18

您可以通过使用 注册委托来执行此操作ServicePointManager.ServerCertificateValidationCallback 返回 true。如果委托返回 true,则所有证书(有效和无效)都将被接受。

You can do this by registering a delegate with ServicePointManager.ServerCertificateValidationCallback that returns true. If the delegate returns true all certificates (valid as well as invalid) will be accepted.

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