/// <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(); }
public void VerifyXmlDataService(string scriptPath, XdsRequestDocument requestDocument, bool?compress, bool?security) { var serializer = GetSerializer(compress, security); var requestBytes = serializer.Serialize(requestDocument.ConvertToBytes()); // NOTE : SILVERLIGHT에서는 UploadDataAsync 메소드를 지원하지 않는다. Silverlight에서는 WebService나 WCF를 사용해야 한다. var webClient = new WebClient(); var responseBytes = webClient.UploadData(scriptPath, requestBytes); var xdsResponse = ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument(); Assert.IsNotNull(xdsResponse); Assert.IsFalse(xdsResponse.HasError); }
public void VerifyXmlDataServiceAsync(string scriptPath, XdsRequestDocument requestDocument, bool?compress, bool?security) { var serializer = GetSerializer(compress, security); var requestBytes = serializer.Serialize(requestDocument.ConvertToBytes()); var webClient = new WebClient(); var uploadTask = webClient.UploadDataTask(new Uri(scriptPath), "POST", requestBytes); uploadTask.Wait(); var responseBytes = uploadTask.Result; var xdsResponse = ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument(); Assert.IsNotNull(xdsResponse); Assert.IsFalse(xdsResponse.HasError); }
private static void VerifyXmlDataServiceAsync(XdsRequestDocument xdsRequest, string productName, bool?compress, bool?security) { var waitHandle = new AutoResetEvent(false); var serializer = GetSerializer(compress, security); var requestBytes = serializer.Serialize(xdsRequest.ConvertToBytes()); var proxy = new XmlDataServiceClient(); if (security.GetValueOrDefault(false)) { // IAsyncResult를 반환받아서 필요할 때 기다리게 할 수도 있지만, 테스트를 위해 Synchronous하게 동작하게 한다. proxy.BeginExecuteSecurity(requestBytes, productName, compress.GetValueOrDefault(false), (ar) => { var proxy2 = (XmlDataServiceClient)ar.AsyncState; var responseBytes = proxy2.EndExecuteSecurity(ar); var xdsResponse = ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument(); Assert.IsNotNull(xdsResponse); Assert.IsFalse(xdsResponse.HasError); Assert.IsTrue(xdsResponse.Responses.Count > 0); proxy2.Close(); }, proxy); } else { // IAsyncResult를 반환받아서 필요할 때 기다리게 할 수도 있지만, 테스트를 위해 Synchronous하게 동작하게 한다. proxy.BeginExecute(requestBytes, productName, compress.GetValueOrDefault(false), (ar) => { var proxy2 = (XmlDataServiceClient)ar.AsyncState; var responseBytes = proxy2.EndExecute(ar); var xdsResponse = ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument(); Assert.IsNotNull(xdsResponse); Assert.IsFalse(xdsResponse.HasError); Assert.IsTrue(xdsResponse.Responses.Count > 0); proxy2.Close(); }, proxy); } }
private static void VerifyXmlDataService(XdsRequestDocument xdsRequest, string productName, bool?compress, bool?security) { using (var xdsProxy = new XmlDataServiceClient()) { var serializer = GetSerializer(compress, security); var requestBytes = serializer.Serialize(xdsRequest.ConvertToBytes()); var responseBytes = security.GetValueOrDefault(false) ? xdsProxy.ExecuteSecurity(requestBytes, productName, compress.GetValueOrDefault(false)) : xdsProxy.Execute(requestBytes, productName, compress.GetValueOrDefault(false)); Assert.IsNotNull(responseBytes); var xdsResponse = ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument(); Assert.IsNotNull(xdsResponse); Assert.IsFalse(xdsResponse.HasError); Assert.IsTrue(xdsResponse.Responses.Count > 0); } }