/// <summary> /// Calls the HMRC Gateway web-service to retrieve the current status of the /// VAT Submission supplied in the Document Record, and returns an XML string /// of the results. /// </summary> /// <param name="record"></param> /// <returns></returns> private string RetrieveHMRCResponse(DocumentRecord record) { VAT100_Poll pollMessage = new VAT100_Poll(); pollMessage.Header.MessageDetails.Class = record.docClass; pollMessage.Header.MessageDetails.CorrelationID = record.theDocument.correlationID; string pollMsg; // Serialize the message to a string XmlSerializer xmlSerializer = new XmlSerializer(pollMessage.GetType()); //SS:04/06/2018:2018-R1:ABSEXCH-20538:VAT 100 Submissions failing due to HMRC gateway changes using (Utf8StringWriter textWriter = new Utf8StringWriter()) { xmlSerializer.Serialize(textWriter, pollMessage); pollMsg = textWriter.ToString(); } // Submit the resulting XML to HMRC // Create a request var request = (HttpWebRequest)WebRequest.Create(FPendingDocument.theDocument.PollingURL); var data = Encoding.ASCII.GetBytes(pollMsg); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; // Write the data to the request parameters using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } // Send the request and get the response. var response = (HttpWebResponse)request.GetResponse(); // Get the response in a stream. var responseData = new StreamReader(response.GetResponseStream()).ReadToEnd(); // Convert the stream to a string string responseXML = responseData.ToString(); return(responseXML); }
private void btnPoll_Click(object sender, EventArgs e) { DocumentRecord record = new DocumentRecord(); btnPoll.Enabled = false; btnDelete.Enabled = false; pollTimer.Enabled = true; VAT100_Poll pollMessage = new VAT100_Poll(); pollMessage.Header.MessageDetails.Class = "HMRC-VAT-DEC"; pollMessage.Header.MessageDetails.CorrelationID = editCorrelationID.Text; string pollMsg; // Serialize the message to a string XmlSerializer xmlSerializer = new XmlSerializer(pollMessage.GetType()); //SS:04/06/2018:2018-R1:ABSEXCH-20538:VAT 100 Submissions failing due to HMRC gateway changes using (Utf8StringWriter textWriter = new Utf8StringWriter()) { xmlSerializer.Serialize(textWriter, pollMessage); pollMsg = textWriter.ToString(); } // Submit the resulting XML to HMRC // Create a request var request = (HttpWebRequest)WebRequest.Create(comboTargetURL.Text /* + @"\poll" */); var data = Encoding.ASCII.GetBytes(pollMsg); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; // Write the data to the request parameters using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } // Send the request and get the response. WebResponse response = null; try { response = (HttpWebResponse)request.GetResponse(); } catch (Exception ex) { textNarrative.AppendText("Error submitting Poll request\r\n" + ex.Message); return; } // Get the response in a stream. var responseData = new StreamReader(response.GetResponseStream()).ReadToEnd(); // Convert the stream to a string string responseXML = responseData.ToString(); HandleHMRCResponse(responseXML); }