如何在Web服务请求中忽略SSL证书错误?

3
问题:我编写了一个控制台程序,使用SQL Server 2005 Web服务将报告上传到SQL Server 2005报告服务(这样我就不必手动上传100个报告)。 在本地和远程都可以正常工作。但现在的问题是有一个服务器使用SSL,所以rs.Url =“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个回答

8

1
只需要添加这一行代码:System.Net.ServicePointManager.ServerCertificateValidationCallback = Function() True - Stefan Steiger

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接