asp.net - Error : The underlying connection was closed: The connection was closed unexpectedly. -
i tried suggestions in other posts , didn't work. i'm getting error when tried send request , getting response getresponse().
my codes this,
protected string createsalerequest(double amount, int installment) { string request = ""; try { xmlnode node = null; xmldocument _msgtemplate = new xmldocument(); _msgtemplate.loadxml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><epaymentmsg versioninfo=\"2.0\" tt=\"request\" rm=\"direct\" ct=\"money\">" + "<operation actiontype=\"sale\"><opdata><merchantinfo merchantid=\"\" merchantpassword=\"\" />" + "<actioninfo><trnxcommon trnxid=\"\" protocol=\"156\"><amountinfo amount=\"0\" currency=\"792\" /></trnxcommon><paymenttypeinfo>" + "<installmentinfo numberofinstallments=\"0\" /></paymenttypeinfo></actioninfo><paninfo pan=\"\" expirydate=\"\" cvv2=\"\" brandid=\"\" />" + "<orderinfo><orderline>0</orderline></orderinfo><orgtrnxinfo /><customdata></customdata><cardholderip></cardholderip></opdata></operation></epaymentmsg>"); node = _msgtemplate.selectsinglenode("//epaymentmsg/operation/opdata/merchantinfo"); node.attributes["merchantid"].value = "006100200140200"; node.attributes["merchantpassword"].value = "123"; node = _msgtemplate.selectsinglenode("//epaymentmsg/operation/opdata/actioninfo/trnxcommon"); node.attributes["trnxid"].value = guid.newguid().tostring(); node = _msgtemplate.selectsinglenode("//epaymentmsg/operation/opdata/actioninfo/trnxcommon/amountinfo"); string gonderilecekamount = amount.tostring("####.00"); gonderilecekamount = gonderilecekamount.replace(",", "."); node.attributes["amount"].value = gonderilecekamount; node.attributes["currency"].value = "949"; node = _msgtemplate.selectsinglenode("//epaymentmsg/operation/opdata/actioninfo/paymenttypeinfo/installmentinfo"); node.attributes["numberofinstallments"].value = "0"; node = _msgtemplate.selectsinglenode("//epaymentmsg/operation/opdata/paninfo"); node.attributes["pan"].value = "4022751585445574"; node.attributes["expirydate"].value = "201406"; node.attributes["cvv2"].value = "408"; node.attributes["brandid"].value = "visa"; node = _msgtemplate.selectsinglenode("//epaymentmsg/operation/opdata/cardholderip"); node.innertext = "10.20.30.40"; request = _msgtemplate.outerxml; return request; } catch (exception ex) { throw ex; } } public string send(string request) { try { string postdata = ""; string responsedata = ""; system.text.encoding encoding = system.text.encoding.getencoding("iso-8859-9"); postdata = "https://vpstest.bankasya.com.tr/iposnet/sposnet.aspx?prmstr=[data]"; postdata = postdata.replace("[data]", request); httpwebrequest webreq = (httpwebrequest)webrequest.create(postdata); webreq.timeout = convert.toint32(20000); webreq.keepalive = false; webreq.protocolversion = httpversion.version10; webresponse webresp = webreq.getresponse(); stream respstream = webresp.getresponsestream(); byte[] buffer = new byte[10000]; int len = 0, r = 1; while (r > 0) { r = respstream.read(buffer, len, 10000 - len); len += r; } respstream.close(); responsedata = encoding.getstring(buffer, 0, len).replace("\r", "").replace("\n", ""); return responsedata; } catch (system.net.sockets.socketexception ex) { throw ex; } catch (webexception ex) { if (ex.status == webexceptionstatus.serverprotocolviolation) { response.write("status code : {0} " + ((httpwebresponse)ex.response).statuscode); response.write("status description : {0} " + ((httpwebresponse)ex.response).statusdescription); } throw ex; } catch (exception ex) { throw ex; } }
which tried,
<httpruntime maxrequestlength="409600" executiontimeout="900"/>
<system.net> <settings> <httpwebrequest useunsafeheaderparsing="true" /> </settings> </system.net>
webreq.keepalive = false; webreq.protocolversion = httpversion.version10; webreq.timeout = 1000000000; webreq.readwritetimeout = 1000000000;
note : there's test info's in code. not real values.
there error on bank's wcf systems. code working now.
Comments
Post a Comment