Mono c#在一台Linux机器上工作得很好,但在另一台机器上却不行!也许和证书有关
本文关键字:一台 机器 也许 证书 工作 Linux Mono 很好 | 更新日期: 2023-09-27 18:04:08
我有一些调用soap服务的代码。
它在我的第一台linux机器上运行良好。
然而,当我在另一台机器上运行它时,我得到了下面的错误:
谷歌似乎显示它可能来自证书,虽然我不确定这一点,因为我通过ServicePointManager.ServerCertificateValidationCallback = Validator;
重写证书方法其中Validator
是返回true的函数。
任何想法?
Unhandled Exception: System.Net.WebException: Error getting response stream (ReadDone1): ReceiveFailure ---> System.IO.IOException: EndRead failure ---> System.Net.Sockets.SocketException: Connection reset by peer
at System.Net.Sockets.Socket.EndReceive (IAsyncResult result) [0x00000] in <filename unknown>:0
at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.SslStreamBase.InternalReadCallback (IAsyncResult result) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
at CRMOnlineSOAPRequests.CRMHelper.GetSOAPResponse (System.String url, System.String soapEnvelope) [0x00000] in <filename unknown>:0
at CRMOnlineSOAPRequests.CRMHelper.createEntity (System.String[] keyValuesOneDimensionalArray) [0x00000] in <filename unknown>:0
at CRMCreateEntity.Program.Main (System.String[] keyValuesOneDimensionalArray) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.WebException: Error getting response stream (ReadDone1): ReceiveFailure ---> System.IO.IOException: EndRead failure ---> System.Net.Sockets.SocketException: Connection reset by peer
at System.Net.Sockets.Socket.EndReceive (IAsyncResult result) [0x00000] in <filename unknown>:0
at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.SslStreamBase.InternalReadCallback (IAsyncResult result) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
at CRMOnlineSOAPRequests.CRMHelper.GetSOAPResponse (System.String url, System.String soapEnvelope) [0x00000] in <filename unknown>:0
at CRMOnlineSOAPRequests.CRMHelper.createEntity (System.String[] keyValuesOneDimensionalArray) [0x00000] in <filename unknown>:0
at CRMCreateEntity.Program.Main (System.String[] keyValuesOneDimensionalArray) [0x00000] in <filename unknown>:0
我们公司的证书出了问题,另一家公司希望我们使用在线生成的证书,而不是"官方"证书。我们不希望将该证书包含在我们的信任列表中,因为其他公司也可能使用它。因此,我们使用以下代码暂时接受所有证书,然后重置证书处理:
System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
{
//Whatever the certificate, accept it.
return true;
};
//Do your request
//Reset handling to normal.
System.Net.ServicePointManager.ServerCertificateValidationCallback = null;
请注意,这是在。net不是单声道,所以我不确定它是否会工作