Ejemplo n.º 1
0
        public ISMEV3Response GetStatus()
        {
            var result = new SMEV3ResponseResult();

            try
            {
                var timestamp = new Timestamp();
                timestamp.Id    = "SIGNED_BY_CONSUMER";
                timestamp.Value = DateTime.UtcNow.ToString("o");

                var request  = new GetStatus(timestamp, null);
                var smevSign = SerializeWithSign(request, "SIGNED_BY_CONSUMER");
                request.CallerInformationSystemSignature = smevSign;

                var response = smev.GetStatus(request);
                result.SoapRequest  = behavior.SoapRequest;
                result.SoapResponse = behavior.SoapResponse;

                if (response.SmevAsyncProcessingMessage == null)
                {
                    result.Status = SMEV3ResultStatus.QueueEmpty;
                    return(result);
                }
                var asyncstatus = response.SmevAsyncProcessingMessage.AsyncProcessingStatusData.AsyncProcessingStatus;
                result.MessageId         = response.SmevAsyncProcessingMessage.AsyncProcessingStatusData.Id;
                result.OriginalMessageId = asyncstatus.OriginalMessageId;
                result.MessageType       = SMEV3MessageType.Response;
                result.Status            = SMEV3ResultStatus.Reject;

                if (asyncstatus.StatusCategory == InteractionStatusType.underProcessing ||
                    asyncstatus.StatusCategory == InteractionStatusType.requestIsQueued ||
                    asyncstatus.StatusCategory == InteractionStatusType.requestIsAcceptedBySmev ||
                    asyncstatus.StatusCategory == InteractionStatusType.responseIsAcceptedBySmev)
                {
                    result.Status = SMEV3ResultStatus.UnderProcessing;
                }
                else if (asyncstatus.StatusCategory == InteractionStatusType.cancelled ||
                         asyncstatus.StatusCategory == InteractionStatusType.requestIsRejectedBySmev ||
                         asyncstatus.StatusCategory == InteractionStatusType.doesNotExist)
                {
                    result.Status = SMEV3ResultStatus.Reject;
                }
                result.ErrorText = asyncstatus.SmevFault == null ? asyncstatus.StatusDetails :
                                   (asyncstatus.StatusDetails + "\n" + asyncstatus.SmevFault.Code + " " + asyncstatus.SmevFault.Description);
            }
            catch (FaultException e)
            {
                result.SoapRequest  = behavior.SoapRequest;
                result.SoapResponse = behavior.SoapResponse;
                result.Status       = SMEV3ResultStatus.Fail;
                result.ErrorText    = e.Message;
            }
            catch (Exception e)
            {
                result.Status     = SMEV3ResultStatus.Error;
                result.ErrorText  = e.Message;
                result.ErrorText += "\n" + e.StackTrace;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// После получения ответа необходимо подтвердить получение методом Ack
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="namespaceuri"></param>
        /// <param name="rootname">Имя корневого элемента вида сведений, если null, берется имя класса</param>
        /// <returns></returns>
        public ISMEV3Response GetResponse()
        {
            var result = new SMEV3ResponseResult();

            try
            {
                var messageSelector = new MessageTypeSelector();
                messageSelector.Id        = "SIGNED_BY_CALLER";
                messageSelector.Timestamp = DateTime.Now;

                //var type = typeof(T);
                //var root = type.GetCustomAttributes(typeof(XmlRootAttribute), false).Select(o => (XmlRootAttribute)o).First();
                //messageSelector.RootElementLocalName = string.IsNullOrWhiteSpace(root.ElementName) ? type.Name : root.ElementName;
                //messageSelector.NamespaceURI = root.Namespace;

                var request  = new GetResponse(messageSelector, null);
                var smevSign = SerializeWithSign(request, "SIGNED_BY_CALLER");
                request.CallerInformationSystemSignature = smevSign;

                var response = smev.GetResponse(request);
                result.SoapRequest  = behavior.SoapRequest;
                result.SoapResponse = behavior.SoapResponse;

                if (response.ResponseMessage == null)
                {
                    result.Status = SMEV3ResultStatus.QueueEmpty;
                    return(result);
                }

                var status = response.ResponseMessage.Response.MessageMetadata.Status;
                if (status == InteractionStatusType.responseIsDelivered)
                {
                    result.Status            = SMEV3ResultStatus.OK;
                    result.MessageId         = response.ResponseMessage.Response.SenderProvidedResponseData.MessageID;
                    result.OriginalMessageId = response.ResponseMessage.Response.OriginalMessageId;
                    result.MessageType       = (SMEV3MessageType)response.ResponseMessage.Response.MessageMetadata.MessageType;

                    if (response.ResponseMessage.Response.SenderProvidedResponseData.MessagePrimaryContent != null)
                    {
                        result.ResponseData = response.ResponseMessage.Response.SenderProvidedResponseData.MessagePrimaryContent;

                        if (response.ResponseMessage.AttachmentContentList != null || response.ResponseMessage.Response.FSAttachmentsList != null)
                        {
                            result.Attachments = new Dictionary <string, byte[]>();
                        }

                        // Получение через MTOM
                        if (response.ResponseMessage.Response.SenderProvidedResponseData.AttachmentHeaderList != null)
                        {
                            foreach (var attachmentContent in response.ResponseMessage.AttachmentContentList)
                            {
                                var filename = attachmentContent.Id;

                                /*var header = response.ResponseMessage.Response.SenderProvidedResponseData.AttachmentHeaderList.FirstOrDefault(o => o.contentId == attachmentContent.Id);
                                 *                              if (header != null)
                                 *                              {
                                 *                                      var ext = header.MimeType;
                                 *                                      filename += ext;
                                 *                              }*/
                                result.Attachments.Add(filename, attachmentContent.Content);
                            }
                        }
                        // Получение через FTP
                        else if (response.ResponseMessage.Response.SenderProvidedResponseData.RefAttachmentHeaderList != null)
                        {
                            foreach (var info in response.ResponseMessage.Response.FSAttachmentsList)
                            {
                                var bytes = FtpDownLoad(info);
                                result.Attachments.Add(info.FileName, bytes);
                            }
                        }
                    }
                    else if (response.ResponseMessage.Response.SenderProvidedResponseData.AsyncProcessingStatus != null)
                    {
                        var asyncstatus = response.ResponseMessage.Response.SenderProvidedResponseData.AsyncProcessingStatus;
                        result.OriginalMessageId = asyncstatus.OriginalMessageId;
                        result.Status            = SMEV3ResultStatus.Reject;

                        if (asyncstatus.StatusCategory == InteractionStatusType.underProcessing ||
                            asyncstatus.StatusCategory == InteractionStatusType.requestIsQueued ||
                            asyncstatus.StatusCategory == InteractionStatusType.requestIsAcceptedBySmev ||
                            asyncstatus.StatusCategory == InteractionStatusType.responseIsAcceptedBySmev)
                        {
                            result.Status = SMEV3ResultStatus.UnderProcessing;
                        }
                        else if (asyncstatus.StatusCategory == InteractionStatusType.cancelled ||
                                 asyncstatus.StatusCategory == InteractionStatusType.requestIsRejectedBySmev ||
                                 asyncstatus.StatusCategory == InteractionStatusType.doesNotExist)
                        {
                            result.Status = SMEV3ResultStatus.Reject;
                        }
                        result.ErrorText = asyncstatus.SmevFault == null ? asyncstatus.StatusDetails :
                                           (asyncstatus.StatusDetails + "\n" + asyncstatus.SmevFault.Code + " " + asyncstatus.SmevFault.Description);
                    }
                    else if (response.ResponseMessage.Response.SenderProvidedResponseData.RequestRejected != null)
                    {
                        var requestrejecteds = response.ResponseMessage.Response.SenderProvidedResponseData.RequestRejected;
                        result.OriginalMessageId = response.ResponseMessage.Response.OriginalMessageId;
                        foreach (var requestrejected in requestrejecteds)
                        {
                            result.ErrorText += requestrejected.RejectionReasonCode.ToString() + " " + requestrejected.RejectionReasonDescription;
                        }
                        result.Status = SMEV3ResultStatus.Reject;
                    }
                    // ------------- Пока непонятно нужно ли это обрабатывать ---------------
                    else if (response.ResponseMessage.Response.SenderProvidedResponseData.RequestStatus != null)
                    {
                        var requeststatus = response.ResponseMessage.Response.SenderProvidedResponseData.RequestStatus;
                        result.ErrorText = requeststatus.StatusDescription;
                        result.Status    = SMEV3ResultStatus.UnderProcessing;
                    }
                }
                else
                {
                    result.Status    = SMEV3ResultStatus.Fail;
                    result.ErrorText = "Статус сообщения, обработка которого не была предусмотрена";
                }
            }
            catch (FaultException e)
            {
                result.SoapRequest  = behavior.SoapRequest;
                result.SoapResponse = behavior.SoapResponse;
                result.Status       = SMEV3ResultStatus.Fail;
                result.ErrorText    = e.Message;
            }
            catch (Exception e)
            {
                result.Status     = SMEV3ResultStatus.Error;
                result.ErrorText  = e.Message;
                result.ErrorText += "\n" + e.StackTrace;
            }

            return(result);
        }