代码之家  ›  专栏  ›  技术社区  ›  Stefan Steiger

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

  •  3
  • Stefan Steiger  · 技术社区  · 14 年前

    问:我编写了一个控制台程序,它使用SQLServer2005Web服务将报表上载到SQLServer2005ReportingService(这样我就不必每次手动上载100个报表)。

    但是现在,问题是一个服务器使用SSL 所以呢rs.网址= "https://hostname/ReportServer/reportservice2005.asmx

    现在的问题是SSL证书无效。。。 如何使用Web服务实现这一点?

     ' 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
    
    1 回复  |  直到 14 年前
        1
  •  8
  •   MickeyfAgain_BeforeExitOfSO    11 年前

    ServicePointManager.ServerCertificateValidationCallback 这是真的。如果委托返回true,将接受所有证书(有效和无效)。