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

编程入门 行业动态 更新时间:2024-10-21 14:26:23
本文介绍了如何忽略 WebService 请求中的 SSL 证书错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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).

它在本地和远程都可以正常工作.但是现在,问题是一台服务器使用 SSL所以 rs.Url = "hostname/ReportServer/reportservice2005.asmx

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

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

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?

' msdn.microsoft/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

推荐答案

您可以通过使用 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.

更多推荐

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

本文发布于:2023-11-07 22:54:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:证书   错误   WebService   SSL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!