//This actually calls the service to perform the tax calculation, and returns the calculation result.
        public static GetTaxResult Get(GetTaxRequest req, string acctNum, string licKey, string companyCode, string webAddr)
        {
            //Company Code is ususally maintiained with the account credentials, so it's passed in to this function even though it's included in the body of the GetTaxRequest.
            req.CompanyCode = companyCode;


            //Convert the request to XML
            XmlSerializerNamespaces namesp = new XmlSerializerNamespaces();

            namesp.Add("", "");
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;
            XmlSerializer x  = new XmlSerializer(req.GetType());
            StringBuilder sb = new StringBuilder();

            x.Serialize(XmlTextWriter.Create(sb, settings), req, namesp);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(sb.ToString());
            //doc.Save(@"get_tax_request.xml");

            //Call the service
            Uri            address = new Uri(webAddr + "tax/get");
            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

            request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(acctNum + ":" + licKey)));
            request.Method        = "POST";
            request.ContentType   = "text/xml";
            request.ContentLength = sb.Length;
            Stream newStream = request.GetRequestStream();

            newStream.Write(ASCIIEncoding.ASCII.GetBytes(sb.ToString()), 0, sb.Length);
            GetTaxResult result = new GetTaxResult();

            try
            {
                WebResponse   response = request.GetResponse();
                XmlSerializer r        = new XmlSerializer(result.GetType());
                result = (GetTaxResult)r.Deserialize(response.GetResponseStream());
            }
            catch (WebException ex)
            {
                XmlSerializer r = new XmlSerializer(result.GetType());
                result = (GetTaxResult)r.Deserialize(((HttpWebResponse)ex.Response).GetResponseStream());
            }
            return(result);
        }
Example #2
0
        // This actually calls the service to perform the tax calculation, and returns the calculation result.
        public GetTaxResult GetTax(GetTaxRequest req)
        {
            // Convert the request to XML
            XmlSerializerNamespaces namesp = new XmlSerializerNamespaces();

            namesp.Add(string.Empty, string.Empty);
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;
            XmlSerializer x  = new XmlSerializer(req.GetType());
            StringBuilder sb = new StringBuilder();

            x.Serialize(XmlTextWriter.Create(sb, settings), req, namesp);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(sb.ToString());

            // Call the service
            Uri            address = new Uri(svcURL + "tax/get");
            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

            request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(accountNum + ":" + license)));
            request.Method        = "POST";
            request.ContentType   = "text/xml";
            request.ContentLength = sb.Length;
            Stream newStream = request.GetRequestStream();

            newStream.Write(ASCIIEncoding.ASCII.GetBytes(sb.ToString()), 0, sb.Length);
            GetTaxResult result = new GetTaxResult();

            try
            {
                WebResponse   response = request.GetResponse();
                XmlSerializer r        = new XmlSerializer(result.GetType());
                result = (GetTaxResult)r.Deserialize(response.GetResponseStream());
            }
            catch (WebException ex)
            {
                XmlSerializer r = new XmlSerializer(result.GetType());
                result = (GetTaxResult)r.Deserialize((ex.Response).GetResponseStream());
            }

            return(result);
        }
Example #3
0
        // This actually calls the service to perform the tax calculation, and returns the calculation result.
        public GetTaxResult GetTax(GetTaxRequest req)
        {
            // Convert the request to XML
            XmlSerializerNamespaces namesp = new XmlSerializerNamespaces();
            namesp.Add(string.Empty, string.Empty);
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = true;
            XmlSerializer x = new XmlSerializer(req.GetType());
            StringBuilder sb = new StringBuilder();
            x.Serialize(XmlTextWriter.Create(sb, settings), req, namesp);
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(sb.ToString());

            // Call the service
            Uri address = new Uri(svcURL + "tax/get");
            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
            request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(accountNum + ":" + license)));
            request.Method = "POST";
            request.ContentType = "text/xml";
            request.ContentLength = sb.Length;
            Stream newStream = request.GetRequestStream();
            newStream.Write(ASCIIEncoding.ASCII.GetBytes(sb.ToString()), 0, sb.Length);
            GetTaxResult result = new GetTaxResult();
            try
            {
                WebResponse response = request.GetResponse();
                XmlSerializer r = new XmlSerializer(result.GetType());
                result = (GetTaxResult)r.Deserialize(response.GetResponseStream());
            }
            catch (WebException ex)
            {
                XmlSerializer r = new XmlSerializer(result.GetType());
                result = (GetTaxResult)r.Deserialize((ex.Response).GetResponseStream());
            }

            return result;
        }
        //This actually calls the service to perform the tax calculation, and returns the calculation result.
        public static GetTaxResult Get(GetTaxRequest req, string acctNum, string licKey, string companyCode, string webAddr)
        {
            //Company Code is ususally maintiained with the account credentials, so it's passed in to this function even though it's included in the body of the GetTaxRequest.
            req.CompanyCode = companyCode;

            //Convert the request to XML
            XmlSerializerNamespaces namesp = new XmlSerializerNamespaces();
            namesp.Add("", "");
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = true;
            XmlSerializer x = new XmlSerializer(req.GetType());
            StringBuilder sb = new StringBuilder();
            x.Serialize(XmlTextWriter.Create(sb, settings), req, namesp);
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(sb.ToString());
            //doc.Save(@"get_tax_request.xml");

            //Call the service
            Uri address = new Uri(webAddr + "tax/get");
            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
            request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(acctNum + ":" + licKey)));
            request.Method = "POST";
            request.ContentType = "text/xml";
            request.ContentLength = sb.Length;
            Stream newStream = request.GetRequestStream();
            newStream.Write(ASCIIEncoding.ASCII.GetBytes(sb.ToString()), 0, sb.Length);
            GetTaxResult result = new GetTaxResult();
            try
            {
                WebResponse response = request.GetResponse();
                XmlSerializer r = new XmlSerializer(result.GetType());
                result = (GetTaxResult)r.Deserialize(response.GetResponseStream());
            }
            catch (WebException ex)
            {
                XmlSerializer r = new XmlSerializer(result.GetType());
                result = (GetTaxResult)r.Deserialize(((HttpWebResponse)ex.Response).GetResponseStream());
            }
            return result;
        }