//This calls CancelTax to void a transaction specified in taxreq public static CancelTaxResult Cancel(GetTaxRequest taxReq, string acctNum, string licKey, string companyCode, string webAddr) { CancelTaxRequest req = new CancelTaxRequest(); req.CompanyCode = taxReq.CompanyCode; req.DocCode = taxReq.DocCode; req.DocType = taxReq.DocType; req.CancelCode = CancelCode.DocVoided; //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(@"cancel_tax_request.xml"); //Call the service Uri address = new Uri(webAddr + "tax/cancel"); 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); CancelTaxResponse cancelResponse = new CancelTaxResponse(); try { WebResponse response = request.GetResponse(); XmlSerializer r = new XmlSerializer(cancelResponse.GetType()); cancelResponse = (CancelTaxResponse)r.Deserialize(response.GetResponseStream()); } catch (WebException ex) { XmlSerializer r = new XmlSerializer(cancelResponse.GetType()); cancelResponse = (CancelTaxResponse)r.Deserialize(((HttpWebResponse)ex.Response).GetResponseStream()); if (cancelResponse.ResultCode.Equals(SeverityLevel.Error)) //If the error is returned at the cancelResponse level, translate it to the cancelResult. { cancelResponse.CancelTaxResult = new CancelTaxResult(); cancelResponse.CancelTaxResult.ResultCode = cancelResponse.ResultCode; cancelResponse.CancelTaxResult.Messages = cancelResponse.Messages; } } return(cancelResponse.CancelTaxResult); }
// This calls CancelTax to void a transaction specified in taxreq public CancelTaxResult CancelTax(CancelTaxRequest cancelTaxRequest) { // 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(cancelTaxRequest.GetType()); StringBuilder sb = new StringBuilder(); x.Serialize(XmlTextWriter.Create(sb, settings), cancelTaxRequest, namesp); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); // Call the service Uri address = new Uri(svcURL + "tax/cancel"); 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); CancelTaxResponse cancelResponse = new CancelTaxResponse(); try { WebResponse response = request.GetResponse(); XmlSerializer r = new XmlSerializer(cancelResponse.GetType()); cancelResponse = (CancelTaxResponse)r.Deserialize(response.GetResponseStream()); } catch (WebException ex) { XmlSerializer r = new XmlSerializer(cancelResponse.GetType()); cancelResponse = (CancelTaxResponse)r.Deserialize((ex.Response).GetResponseStream()); // If the error is returned at the cancelResponse level, translate it to the cancelResult. if (cancelResponse.ResultCode.Equals(SeverityLevel.Error)) { cancelResponse.CancelTaxResult = new CancelTaxResult(); cancelResponse.CancelTaxResult.ResultCode = cancelResponse.ResultCode; cancelResponse.CancelTaxResult.Messages = cancelResponse.Messages; } } return(cancelResponse.CancelTaxResult); }
//This calls CancelTax to void a transaction specified in taxreq public static CancelTaxResult Cancel(GetTaxRequest taxReq, string acctNum, string licKey, string companyCode, string webAddr) { CancelTaxRequest req = new CancelTaxRequest(); req.CompanyCode = taxReq.CompanyCode; req.DocCode = taxReq.DocCode; req.DocType = taxReq.DocType; req.CancelCode = CancelCode.DocVoided; //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(@"cancel_tax_request.xml"); //Call the service Uri address = new Uri(webAddr + "tax/cancel"); 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); CancelTaxResponse cancelResponse = new CancelTaxResponse(); try { WebResponse response = request.GetResponse(); XmlSerializer r = new XmlSerializer(cancelResponse.GetType()); cancelResponse = (CancelTaxResponse)r.Deserialize(response.GetResponseStream()); } catch (WebException ex) { XmlSerializer r = new XmlSerializer(cancelResponse.GetType()); cancelResponse = (CancelTaxResponse)r.Deserialize(((HttpWebResponse)ex.Response).GetResponseStream()); if(cancelResponse.ResultCode.Equals(SeverityLevel.Error)) //If the error is returned at the cancelResponse level, translate it to the cancelResult. { cancelResponse.CancelTaxResult = new CancelTaxResult(); cancelResponse.CancelTaxResult.ResultCode = cancelResponse.ResultCode; cancelResponse.CancelTaxResult.Messages = cancelResponse.Messages; } } return cancelResponse.CancelTaxResult; }
// This calls CancelTax to void a transaction specified in taxreq public CancelTaxResult CancelTax(CancelTaxRequest cancelTaxRequest) { // 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(cancelTaxRequest.GetType()); StringBuilder sb = new StringBuilder(); x.Serialize(XmlTextWriter.Create(sb, settings), cancelTaxRequest, namesp); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); // Call the service Uri address = new Uri(svcURL + "tax/cancel"); 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); CancelTaxResponse cancelResponse = new CancelTaxResponse(); try { WebResponse response = request.GetResponse(); XmlSerializer r = new XmlSerializer(cancelResponse.GetType()); cancelResponse = (CancelTaxResponse)r.Deserialize(response.GetResponseStream()); } catch (WebException ex) { XmlSerializer r = new XmlSerializer(cancelResponse.GetType()); cancelResponse = (CancelTaxResponse)r.Deserialize(((HttpWebResponse)ex.Response).GetResponseStream()); // If the error is returned at the cancelResponse level, translate it to the cancelResult. if (cancelResponse.ResultCode.Equals(SeverityLevel.Error)) { cancelResponse.CancelTaxResult = new CancelTaxResult(); cancelResponse.CancelTaxResult.ResultCode = cancelResponse.ResultCode; cancelResponse.CancelTaxResult.Messages = cancelResponse.Messages; } } return cancelResponse.CancelTaxResult; }