Authorize.net getting failed suddenly

Sudhanshum
Sudhanshum used Ask the Experts™
on
Hi I am using Authorize.net for payment gateway in my Asp.net code, It suddenly stopped working few days back, I want to fix that immediately, Please help me,
I am getting error on below line
myWriter = new StreamWriter(objRequest.GetRequestStream()
Error is The exception message is 'The request was aborted: Could not create SSL/TLS secure channel.'. See server logs for more details.
Here is code, My windows machine is Windows server 2008 and I have installed Framework 4.5.

 ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
        String ApiLogin = System.Configuration.ConfigurationManager.AppSettings["ApiLoginL"];
        String TransactionKey = System.Configuration.ConfigurationManager.AppSettings["TransactionKeyL"];

   
        String post_url = "https://secure2.authorize.net/gateway/transact.dll";

        Dictionary<string, string> post_values = new Dictionary<string, string>();

        post_values.Add("x_login", ApiLogin);
        post_values.Add("x_tran_key", TransactionKey);
        post_values.Add("x_delim_data", "TRUE");
        post_values.Add("x_delim_char", "|");
        post_values.Add("x_relay_response", "FALSE");

        post_values.Add("x_type", "AUTH_CAPTURE");
        post_values.Add("x_method", "CC");
        post_values.Add("x_card_num", OrderD.CARDNUMBER);
   
        post_values.Add("x_card_code", OrderD.CVV);
       
        post_values.Add("x_exp_date", OrderD.MONTH + "" + OrderD.YEAR);

        post_values.Add("x_amount", "1");


        post_values.Add("x_description", "");

        StrSql = "SELECT USERID, FIRSTNAME,LASTNAME,COMPANYNAME,(STREETADDRESS1||' '||STREETADDRESS2)ADDRESS,STATE,ZIPCODE,CITY,COUNTRY FROM USERCONTACTS ";
        StrSql = StrSql + "WHERE USERID=  " + OrderD.USERID + "  ";
        dt = OdButil.FillDataTable(StrSql, MyConnectionString);


        post_values.Add("x_first_name", dt.Rows[0]["FIRSTNAME"].ToString());
        post_values.Add("x_last_name", dt.Rows[0]["LASTNAME"].ToString());
        post_values.Add("x_company", dt.Rows[0]["COMPANYNAME"].ToString());

        post_values.Add("x_address", dt.Rows[0]["ADDRESS"].ToString());
        post_values.Add("x_state", dt.Rows[0]["STATE"].ToString());
        post_values.Add("x_zip", dt.Rows[0]["ZIPCODE"].ToString());
        post_values.Add("x_city", dt.Rows[0]["CITY"].ToString());
        post_values.Add("x_country", dt.Rows[0]["COUNTRY"].ToString());

        String post_string = "";/* TODO ERROR: Skipped SkippedTokensTrivia */

        foreach (KeyValuePair<string, string> post_value in post_values)/* TODO ERROR: Skipped SkippedTokensTrivia */
            post_string += post_value.Key + "=" + HttpUtility.UrlEncode(post_value.Value) + "&";/* TODO ERROR: Skipped SkippedTokensTrivia */
        post_string = post_string.TrimEnd('&');/* TODO ERROR: Skipped SkippedTokensTrivia */

        //Create an HttpWebRequest object to communicate with Authorize.net
        HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(post_url);/* TODO ERROR: Skipped SkippedTokensTrivia */
        objRequest.Method = "POST";
        objRequest.ContentLength = post_string.Length;
        objRequest.ContentType = post_url;

        //post data is sent as a stream
        StreamWriter myWriter = null;/* TODO ERROR: Skipped SkippedTokensTrivia */
        myWriter = new StreamWriter(objRequest.GetRequestStream());/* TODO ERROR: Skipped SkippedTokensTrivia */
        myWriter.Write(post_string);
        myWriter.Close();

        //returned values are returned as a stream, then read into a string
        String post_response;
        HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
        using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
        {
            post_response = responseStream.ReadToEnd();
            responseStream.Close();
        }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer

Commented:
Their SSL setup seems to be fine.

What does the log provides for information?
Wat have you changed right before it stopped working?

p.s. edit your post and use the CODE button to embed your code into a more readable format.

Author

Commented:
Where to check Log? I have not changed anything, same code working fine on windows7 machine.

Author

Commented:
The server encountered an error processing the request. The exception message is 'The request was aborted: Could not create SSL/TLS secure channel.'. See server logs for more details. The exception stack trace is:

at PriceService.ValidateAUT() in c:\WebSites\PriceWebservice\App_Code\Service .cs:line 347 at SyncInvokeValidateAUT(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

Commented:
The bit level of the server isn't going to impact TLS.  Most likely you need to enable TLS 1.2 on your production server.

https://support.microsoft.com/en-us/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-wi

You can also use IIS Crypto if you would prefer not to dig around in the registry:

https://www.nartac.com/Products/IISCrypto/

I also had to expand the Tls options to make it work for one vendor:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

Open in new window

-saige-

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial