示例#1
0
        //---------------------------------------------------------------------------------------------
        /// <summary>
        /// Sends a request to delete the document from the HMRC front end.
        /// </summary>
        /// <param name="aCorrelationID"></param>
        private void Delete(string aCorrelationID)
        {
            // Compose and send a Delete message
            string deleteMsg;
            VAT100_DeleteRequest deleteRequest = new VAT100_DeleteRequest();

            // The constructor fills in the fixed, mandatory fields.
            // All we need to do is fill in the CorrelationID and Class.
            deleteRequest.Header.MessageDetails.CorrelationID = FPendingDocument.theDocument.correlationID;
            deleteRequest.Header.MessageDetails.Class         = FPendingDocument.docClass;

            // Serialise the request to XML
            using (StringWriter textWriter = new StringWriter())
            {
                XmlSerializer xmlSerializer = new XmlSerializer(deleteRequest.GetType());
                xmlSerializer.Serialize(textWriter, deleteRequest);
                deleteMsg = textWriter.ToString();
            }

            // Submit the resulting XML string to HMRC
            // Create a web request
            var request = (HttpWebRequest)WebRequest.Create(FPendingDocument.theDocument.PollingURL);
            var data    = Encoding.ASCII.GetBytes(deleteMsg);

            // Send the request
            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();

            // Deserialise the response
            VAT100_DeleteResponse responseMsg;

            XmlSerializer serialiser = new XmlSerializer(typeof(VAT100_DeleteResponse));

            using (StringReader reader = new StringReader(responseXML))
            {
                responseMsg = (VAT100_DeleteResponse)(serialiser.Deserialize(reader));
            }

            // There isn't anything to be done with the response.  Also, if we don't delete the document,
            //  it will automatically expire some time in the future, so it doesn't matter if the
            //  response is in error or not.
        }
示例#2
0
        private void Delete(string aCorrelationID)
        {
            // Compose and send a Delete message
            string deleteMsg;
            VAT100_DeleteRequest deleteRequest = new VAT100_DeleteRequest();

            // The constructor fills in the fixed, mandatory fields.
            // All we need to do is fill in the CorrelationID and Class.
            deleteRequest.Header.MessageDetails.CorrelationID = editCorrelationID.Text;
            deleteRequest.Header.MessageDetails.Class         = "HMRC-VAT-DEC";

            // Serialise the request to XML
            using (StringWriter textWriter = new StringWriter())
            {
                XmlSerializer xmlSerializer = new XmlSerializer(deleteRequest.GetType());
                xmlSerializer.Serialize(textWriter, deleteRequest);
                deleteMsg = textWriter.ToString();
            }

            // Submit the resulting XML string to HMRC
            // Create a web request
            var request = (HttpWebRequest)WebRequest.Create(comboTargetURL.Text);
            var data    = Encoding.ASCII.GetBytes(deleteMsg);

            // Send the request
            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();

            HandleHMRCResponse(responseXML);
        }