Пример #1
0
 public void Send(string Link, string QueryFileName, string PathFile)
 {
     try
     {
         this.queryFileName = QueryFileName;
         System.IO.Stream       stream       = System.IO.File.OpenRead(PathFile);
         System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
         stream.CopyTo(memoryStream);
         System.Net.WebClient webClient = new System.Net.WebClient();
         webClient.Headers["Content-type"] = "multipart/form-data; boundary=---------------------------" + _boundaryNo;
         webClient.OpenWriteAsync(new Uri(Link, UriKind.Absolute), "POST", new { Stream = memoryStream, FileName = PathFile });
         webClient.OpenWriteCompleted += new System.Net.OpenWriteCompletedEventHandler(webClient_OpenWriteCompleted);
     }
     catch { Completed = true; }
 }
Пример #2
0
        public static void MultipleLargeDataSets()
        {
            System.Net.Http.HttpMethod meth = System.Net.Http.HttpMethod.Post;

            string fn = "lobster.json.txt";


            using (System.IO.Stream strm = new System.IO.FileStream(fn, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
            {
                MultipleLargeDataSets(strm, GetMultipleDataSetsSQL());
            } // End Using strm

            string endpointUrl = "http://localhost:53417/ajax/dataReceiver.ashx";

            using (System.Net.WebClient client = new System.Net.WebClient())
            {
                client.Headers.Add("Content-Type", "application/json");


                // client.OpenWriteCompleted += (sender, e) =>
                client.OpenWriteCompleted += delegate(object sender, System.Net.OpenWriteCompletedEventArgs e)
                {
                    // System.Net.WebClient that = (System.Net.WebClient) sender;

                    if (e.Error != null)
                    {
                        throw e.Error;
                    }

                    using (System.IO.Stream postStream = e.Result)
                    {
                        MultipleLargeDataSets(postStream, GetMultipleDataSetsSQL());
                        postStream.Flush();
                        postStream.Close();
                    }
                };

                client.OpenWriteAsync(new System.Uri(endpointUrl));


                using (System.IO.Stream postStream = client.OpenWrite(endpointUrl, meth.Method))
                {
                    // postStream.Write(fileContent, 0, fileContent.Length);
                    MultipleLargeDataSets(postStream, GetMultipleDataSetsSQL());
                } // End Using postStream

                using (System.IO.Stream postStream = client.OpenRead(endpointUrl))
                {
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(postStream))
                    {
                        string output = sr.ReadToEnd();
                        System.Console.WriteLine(output);
                    } // End Using sr
                }     // End Using postStream


                // client.ResponseHeaders
            } // End Using client

            DataSetSerialization thisDataSet = EasyJSON.JsonHelper.DeserializeFromFile <DataSetSerialization>(fn);

            System.Console.WriteLine(thisDataSet);
        } // End Sub MultipleLargeDataSets