コード例 #1
0
ファイル: HttpXmlUtility.cs プロジェクト: abansalm/sdk-dotnet
        /// <summary>
        /// Sends the specified API request.
        /// </summary>
        /// <param name="apiRequest">The API request.</param>
        /// <returns></returns>
        public ANetApiResponse Send(ANetApiRequest apiRequest) {

            //Authenticate it
            AuthenticateRequest(apiRequest);

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_serviceUrl);
            webRequest.Method = "POST";
            webRequest.ContentType = "text/xml";
            webRequest.KeepAlive = true;

            // Serialize the request
            var type = apiRequest.GetType();
            var serializer = new XmlSerializer(type);
            XmlWriter writer = new XmlTextWriter(webRequest.GetRequestStream(), Encoding.UTF8);
            serializer.Serialize(writer, apiRequest);
            writer.Close();


            // Get the response
            WebResponse webResponse = webRequest.GetResponse();

            // Load the response from the API server into an XmlDocument.
            _xmlDoc = new XmlDocument();
            _xmlDoc.Load(XmlReader.Create(webResponse.GetResponseStream()));


            var response = DecideResponse(_xmlDoc);
            CheckForErrors(response);
            return response;
        }
コード例 #2
0
        /// <summary>
        /// Sends the specified API request.
        /// </summary>
        /// <param name="apiRequest">The API request.</param>
        /// <returns></returns>
        public ANetApiResponse Send(ANetApiRequest apiRequest) {

            //Authenticate it
            AuthenticateRequest(apiRequest);

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_serviceUrl);
            webRequest.Method = "POST";
            webRequest.ContentType = "text/xml";
            webRequest.KeepAlive = true;

            //set the http connection timeout 
            var httpConnectionTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpConnectionTimeout);
            webRequest.Timeout = (httpConnectionTimeout != 0 ? httpConnectionTimeout : Constants.HttpConnectionDefaultTimeout);

            //set the time out to read/write from stream
            var httpReadWriteTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpReadWriteTimeout);
            webRequest.ReadWriteTimeout = (httpReadWriteTimeout != 0 ? httpReadWriteTimeout : Constants.HttpReadWriteDefaultTimeout);

            // Serialize the request
            var type = apiRequest.GetType();
            var serializer = new XmlSerializer(type);
            XmlWriter writer = new XmlTextWriter(webRequest.GetRequestStream(), Encoding.UTF8);
            serializer.Serialize(writer, apiRequest);
            writer.Close();


            // Get the response
            WebResponse webResponse = webRequest.GetResponse();

            // Load the response from the API server into an XmlDocument.
            _xmlDoc = new XmlDocument();
            _xmlDoc.Load(XmlReader.Create(webResponse.GetResponseStream()));


            var response = DecideResponse(_xmlDoc);
            CheckForErrors(response);
            return response;
        }
コード例 #3
0
ファイル: HttpXmlUtility.cs プロジェクト: abansalm/sdk-dotnet
 /// <summary>
 /// Adds authentication information to the request.
 /// </summary>
 /// <param name="request">The request.</param>
 void AuthenticateRequest(ANetApiRequest request) {
     request.merchantAuthentication = new merchantAuthenticationType();
     request.merchantAuthentication.name = _apiLogin;
     request.merchantAuthentication.Item = _transactionKey;
     request.merchantAuthentication.ItemElementName = ItemChoiceType.transactionKey;
 }
コード例 #4
0
 /// <summary>
 /// Adds authentication information to the request.
 /// </summary>
 /// <param name="request">The request.</param>
 void AuthenticateRequest(ANetApiRequest request)
 {
     request.merchantAuthentication = new merchantAuthenticationType();
     request.merchantAuthentication.name = _apiLogin;
     request.merchantAuthentication.transactionKey = _transactionKey;
 }