public override ResponseMessage RunDataService(RequestMessage requestMessage)
        {
            using (var client = new WebDataService.DataService()) {
                var requestBytes = DataServiceTool.ResolveRequestSerializer(ProductName).Serialize(requestMessage);

                var tcs = new TaskCompletionSource <byte[]>();
                ExecuteCompletedEventHandler handler = null;
                handler =
                    (sender, args) =>
                    Parallelism.Tools.EventAsyncPattern.HandleCompletion(tcs, args, () => args.Result,
                                                                         () => client.ExecuteCompleted -= handler);

                client.ExecuteCompleted += handler;

                try {
                    client.ExecuteAsync(requestBytes, ProductName, tcs);
                }
                catch (Exception ex) {
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorException("웹서비스 비동기 호출에 예외가 발생했습니다.", ex);
                    }

                    client.ExecuteCompleted -= handler;
                    tcs.TrySetException(ex);
                }

                var responseBytes = tcs.Task.Result;

                return(DataServiceTool.ResolveResponseSerializer(ProductName).Deserialize(responseBytes));
            }
        }
Exemplo n.º 2
0
        public override XdsResponseDocument ExecuteXmlDataManager(XdsRequestDocument requestDocument)
        {
            using (var xdsService = new XmlDataService()) {
                var adapter = XmlDataTool.ResolveXmlDataManagerAdapter(ProductName);

                var tcs = new TaskCompletionSource <byte[]>(null);

                ExecuteCompletedEventHandler handler = null;
                handler =
                    (s, e) => EventAsyncPattern.HandleCompletion(tcs, e, () => e.Result, () => xdsService.ExecuteCompleted -= handler);
                xdsService.ExecuteCompleted += handler;

                try {
                    var requestBytes = adapter.RequestSerializer.Serialize(requestDocument);
                    xdsService.ExecuteAsync(requestBytes, ProductName, false, tcs);
                }
                catch (Exception ex) {
                    xdsService.ExecuteCompleted -= handler;
                    tcs.TrySetException(ex);
                }


                tcs.Task.Wait();
                Assert.IsTrue(tcs.Task.IsCompleted);

                return(adapter.ResponseSerializer.Deserialize(tcs.Task.Result));
            }
        }
Exemplo n.º 3
0
        public static Task <ResponseMessage> ExecuteTask(this DataService client,
                                                         RequestMessage requestMessage,
                                                         string productName,
                                                         TaskCompletionSource <byte[]> tcs)
        {
            client.ShouldNotBeNull("client");
            requestMessage.ShouldNotBeNull("requestMessage");

            try {
                var requestBytes = ResolveRequestSerializer(productName).Serialize(requestMessage);

                ExecuteCompletedEventHandler handler = null;
                handler = (sender, e) => EAPCommon.HandleCompletion(tcs, e, () => e.Result, () => client.ExecuteCompleted -= handler);
                client.ExecuteCompleted += handler;

                client.ExecuteAsync(requestBytes, productName, tcs);


                return
                    (tcs.Task
                     .ContinueWith(task => ResolveResponseSerializer(productName).Deserialize(task.Result)));
            }
            catch (Exception ex) {
                if (log.IsErrorEnabled)
                {
                    log.ErrorException("웹서비스를 통한 요청이 실패했습니다.", ex);
                }

                throw;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 비동기적으로 Web Service를 호출합니다. 비동기 호출을 동시다발적으로 호출 시 UserState로 각각의 호출을 구분할 수 있어야 한다.
        /// </summary>
        /// <param name="xdsRequest"></param>
        /// <param name="productName"></param>
        /// <param name="compress"></param>
        /// <param name="security"></param>
        private static void VerifyXmlDataServiceAsync(XdsRequestDocument xdsRequest, string productName, bool?compress, bool?security)
        {
            var serializer   = GetSerializer(compress, security);
            var requestBytes = serializer.Serialize(xdsRequest.ConvertToBytes());
            var xdsService   = new XmlDataService();

            var tcs = new TaskCompletionSource <byte[]>(null);

            if (security.GetValueOrDefault(false))
            {
                ExecuteSecurityCompletedEventHandler handler = null;
                handler =
                    (s, e) =>
                    EventAsyncPattern.HandleCompletion(tcs, e, () => e.Result, () => xdsService.ExecuteSecurityCompleted -= handler);
                xdsService.ExecuteSecurityCompleted += handler;

                try {
                    xdsService.ExecuteSecurityAsync(requestBytes, productName, compress.GetValueOrDefault(false), tcs);
                }
                catch (Exception ex) {
                    xdsService.ExecuteSecurityCompleted -= handler;
                    tcs.TrySetException(ex);
                }
            }
            else
            {
                ExecuteCompletedEventHandler handler = null;
                handler =
                    (s, e) => EventAsyncPattern.HandleCompletion(tcs, e, () => e.Result, () => xdsService.ExecuteCompleted -= handler);
                xdsService.ExecuteCompleted += handler;

                try {
                    xdsService.ExecuteAsync(requestBytes, productName, compress.GetValueOrDefault(false), tcs);
                }
                catch (Exception ex) {
                    xdsService.ExecuteCompleted -= handler;
                    tcs.TrySetException(ex);
                }
            }

            tcs.Task.Wait();
            Assert.IsTrue(tcs.Task.IsCompleted);
            var xdsResponse = ((byte[])serializer.Deserialize(tcs.Task.Result)).ConvertToXdsResponseDocument();

            Assert.IsNotNull(xdsResponse);
            Assert.IsFalse(xdsResponse.HasError);
            Assert.IsTrue(xdsResponse.Responses.Count > 0);

            xdsService.Dispose();
        }