Пример #1
0
        public void BeginSaveCustomerServiceData(CustomerServiceDataEntity customServiceDataEntity, SaveCustomerServiceCallback callback)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(
                new Uri(serverBaseUri, relativeSaveCustomerServiceDataURI));

            request.Method = "POST";

            saveCustomerServiceCallback = callback;

            request.BeginGetRequestStream(delegate(IAsyncResult result)
            {
                HttpWebRequest webRequest = result.AsyncState as HttpWebRequest;
                webRequest.ContentType    = "text/xml";
                Stream requestStream      = webRequest.EndGetRequestStream(result);
                StreamWriter streamWriter = new StreamWriter(requestStream);

                // Serializar los datos a enviar.
                DataContractSerializer serializer = new DataContractSerializer(typeof(CustomerServiceDataEntity));
                serializer.WriteObject(streamWriter.BaseStream, customServiceDataEntity);
                streamWriter.Close();

                // Realizar una llamada asíncrona. Se invocará un Callback sobre un hilo ejecutándose en segundo plano.
                request.BeginGetResponse(new AsyncCallback(EndSaveCustomerServiceData), request);
            }
                                          , request);
        }
Пример #2
0
        public void EndSaveCustomerServiceData(System.IAsyncResult result)
        {
            SaveCustomerServiceResult callResult = new SaveCustomerServiceResult();

            try
            {
                HttpWebRequest  request  = (HttpWebRequest)result.AsyncState;
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);

                // Crear una instancia del deserializador.
                DataContractSerializer serializer = new DataContractSerializer(typeof(bool));

                // Deserializar el resultado.
                bool deserializedResult = (bool)serializer.ReadObject(response.GetResponseStream());

                callResult.Success = deserializedResult;
            }
            catch (SerializationException serializationError)
            {
                Debug.WriteLine(serializationError.Message);
            }
            catch (WebException webError)
            {
                Debug.WriteLine(webError.Message);
            }

            // Si existe un callback, invocarlo.
            if (saveCustomerServiceCallback != null)
            {
                saveCustomerServiceCallback(callResult);
                saveCustomerServiceCallback = null;
            }
        }
Пример #3
0
        public void BeginSaveCustomerService(ServiceDocument serviceDocument, SaveCustomerServiceCallback callback)
        {
            try
            {
                CustomerServiceDataEntity customerServiceData = Utilities.ConvertServiceModelToEntity(serviceDocument, this.dataModelEntity);
                CircularReferencesManager.BrokeCustomerServiceDataCircularReference(customerServiceData);

                SilverlightServicesClient client = Utils.SilverlightServicesClient;
                client.BeginSaveCustomerServiceData(customerServiceData, callback);
            }
            catch (Exception)
            {
                throw;
            }
        }