1

I have some code that calls a soap service.
It works fine on my first linux machine.
However when I run it on another machine I get the error below.
A Google seems to show it may be from certificates, although I'm not sure on this as I'm overriding the certificates method via ServicePointManager.ServerCertificateValidationCallback = Validator; Where Validator is a function that returns true.

Any ideas?

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
tshepang
  • 12,111
  • 21
  • 91
  • 136
Soyeed
  • 263
  • 1
  • 5
  • 12
  • The exception message is "Connection reset by peer", could there be a gateway/router that dislikes you? – sisve Mar 15 '13 at 11:22
  • Did you ever find a solution to this? We're having exactly the same problem. – Pete Apr 08 '14 at 13:09

1 Answers1

0

We had a problem with a certificate in our company, another company wanted us to use a certificate that was online generated, so not an "official" certificate. We didn't want to include that certificate in our trusted list because other companies might also use it. Therefor we used the following code to temporarily accept all certificates and then we reset the certificate handling:

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;

Please regard, this is in .NET not mono, so I am not sure if it will work.

SynerCoder
  • 12,493
  • 4
  • 47
  • 78
  • @AbooSoyeed Weird, but is it only 1 pc that works weird, or only 1 pc that the script works on? Is the server you are trying to connect on behind a firewall and that firewall accepts only certain ips? – SynerCoder Mar 15 '13 at 11:47
  • I'm trying to connect to microsoft dynamics, so i doubt it, i did't have to set any settings for the other server (well actually there are two servers this works with and one it doesn't) – Soyeed Mar 15 '13 at 12:49