【问题标题】:Howto ignore SSL certificate error in WebService request?如何忽略 Web 服务请求中的 SSL 证书错误?
【发布时间】:2010-09-24 13:11:30
【问题描述】:

问题:我编写了一个控制台程序,它使用 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

【问题讨论】:

    标签: web-services ssl reportingservices-2005 ssl-certificate ssrs-2008


    【解决方案1】:

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

    【讨论】:

    • 只需要添加这一行:System.Net.ServicePointManager.ServerCertificateValidationCallback = Function() True
    猜你喜欢
    • 1970-01-01
    • 2019-07-21
    • 2019-09-05
    • 1970-01-01
    • 2011-06-21
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    相关资源
    最近更新 更多