I understand that there were several similar messages for this, but I have not yet found a solution. I try to send some xml to the MPI gateway, but keep getting the following error:
Unable to read data from the transport connection: the existing connection was forcibly closed by the remote host.
Below is the code that I am currently using, but have tried almost every other approach that I can think of, and they all return the same error:
string result = ""; string xml = "<TNSAuthRequest><CardNumber>0123456789</CardNumber><ExpiryDate>1801</ExpiryDate><PurchaseAmt>750</PurchaseAmt><CurrencyCode>826</CurrencyCode><CurrencyExponent>2</CurrencyExponent><CountryCode>826</CountryCode><MerchantName>Mayflower</MerchantName><MerchantId>0123456789</MerchantId><MerchantData>abcdefghijklmnopqrstuvwxyz0123456789</MerchantData><MerchantUrl>example.com</MerchantUrl><NotificationURL>example.com/basket</NotificationURL></TNSAuthRequest>"; var url = "https://mpi.securecxl.com"; byte[] bytes = System.Text.Encoding.ASCII.GetBytes("xmldata=" + xml.ToString()); ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate); var req = (HttpWebRequest)WebRequest.Create(url); req.AllowWriteStreamBuffering = true; req.ContentType = "text/xml"; req.Method = "POST"; //req.ContentLength = bytes.Length; req.KeepAlive = false; req.ProtocolVersion = HttpVersion.Version10; req.ServicePoint.ConnectionLimit = 1; //req.Timeout = -1; try { using (var writer = new StreamWriter(req.GetRequestStream(), Encoding.ASCII)) { writer.WriteLine(bytes); } using (WebResponse resp = req.GetResponse()) { using (StreamReader sr = new StreamReader(resp.GetResponseStream())) { result = sr.ReadToEnd().Trim(); } } } catch (Exception ex) { result = ex.Message + "<br />" + ex.InnerException.Message + "<br /><br />" + xml.Replace("<", "<"); } ViewBag.result = result;
Am basically wandering if someone can see something that might be wrong with the code that might cause this error, or if this is most likely the problem at their end? We tried to work on my local host, our real server and my own personal server (with a completely different IP address) and still get the same result.
Any ideas?
source share