Esempio n. 1
0
        /// <summary>
        /// Bestätigung des Auftrags
        /// </summary>
        /// <param name="orderId">ID des Auftrags</param>
        /// <param name="hash">Hash des öffentlichen Schlüssels</param>
        /// <returns></returns>
        public async Task AcknowledgeOrderAsync(string orderId, byte[] hash)
        {
            var query = new OstcAuftrag
            {
                Auftragsnummer  = orderId,
                hash            = string.Join(string.Empty, hash.Select(x => x.ToString("X2"))),
                ItemElementName = (CompanyNumberType)Enum.Parse(typeof(CompanyNumberType), Sender.SenderId.Type.ToString()),
                Item            = Sender.SenderId.Id,
            };
            var queryData = OstcUtils.Serialize(query, Iso88591);

            ValidateData(queryData, OstcMessageType.OrderData);

            var now     = DateTime.Now;
            var message = new TransportRequestType()
            {
                version         = SupportedVersionsType.Item11,
                profile         = ExtraProfileOstc,
                TransportHeader = CreateRequestHeader(now, OstcDataType.Order, ExtraScenario.RequestWithAcknowledgement),
                TransportBody   = new TransportRequestBodyType
                {
                    Items = new object[]
                    {
                        new DataType
                        {
                            Item = new Base64CharSequenceType()
                            {
                                Value = queryData,
                            },
                        },
                    },
                },
            };

            ValidateRequest(message, OstcMessageType.Order);

            var messageData = OstcExtraSerializer.Iso88591.Serialize(message);
            var request     = CreateRequest(Network.Requests.Order);

            using (var requestStream = await Task.Factory.FromAsync(request.BeginGetRequestStream, request.EndGetRequestStream, null))
            {
                requestStream.Write(messageData, 0, messageData.Length);
            }

            using (var response = await Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null))
            {
                var serializer   = new XmlSerializer(typeof(TransportResponseType));
                var responseData = (TransportResponseType)serializer.Deserialize(response.GetResponseStream());

                var flags = responseData.TransportHeader.GetFlags().ToList();
                if (flags.Any(x => x.weight == ExtraFlagWeight.Error))
                {
                    throw new Ostc2Exception(flags);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Bestätigung des Auftrags
        /// </summary>
        /// <param name="orderId">ID des Auftrags</param>
        /// <param name="hash">Hash des öffentlichen Schlüssels</param>
        /// <returns></returns>
        public async Task AcknowledgeOrderAsync(string orderId, byte[] hash)
        {
            var query = new OstcAuftrag
            {
                Auftragsnummer = orderId,
                hash = string.Join(string.Empty, hash.Select(x => x.ToString("X2"))),
                ItemElementName = (CompanyNumberType)Enum.Parse(typeof(CompanyNumberType), Sender.SenderId.Type.ToString()),
                Item = Sender.SenderId.Id,
            };
            var queryData = OstcUtils.Serialize(query, Iso88591);

            ValidateData(queryData, OstcMessageType.OrderData);

            var now = DateTime.Now;
            var message = new TransportRequestType()
            {
                version = SupportedVersionsType.Item11,
                profile = ExtraProfileOstc,
                TransportHeader = CreateRequestHeader(now, OstcDataType.Order, ExtraScenario.RequestWithAcknowledgement),
                TransportBody = new TransportRequestBodyType
                {
                    Items = new object[]
                    {
                        new DataType 
                        {
                            Item = new Base64CharSequenceType()
                            {
                                Value = queryData,
                            },
                        },
                    },
                },
            };

            ValidateRequest(message, OstcMessageType.Order);

            var messageData = OstcExtraSerializer.Iso88591.Serialize(message);
            var request = CreateRequest(Network.Requests.Order);
            using (var requestStream = await Task.Factory.FromAsync(request.BeginGetRequestStream, request.EndGetRequestStream, null))
            {
                requestStream.Write(messageData, 0, messageData.Length);
            }

            using (var response = await Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null))
            {
                var serializer = new XmlSerializer(typeof(TransportResponseType));
                var responseData = (TransportResponseType)serializer.Deserialize(response.GetResponseStream());

                var flags = responseData.TransportHeader.GetFlags().ToList();
                if (flags.Any(x => x.weight == ExtraFlagWeight.Error))
                    throw new Ostc2Exception(flags);
            }
        }