当前位置: 首页>>代码示例>>C#>>正文


C# WebClient.Close方法代码示例

本文整理汇总了C#中System.Net.WebClient.Close方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.Close方法的具体用法?C# WebClient.Close怎么用?C# WebClient.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了WebClient.Close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WebServiceHelper

 public WebServiceHelper(string Url, string classname)
 {
     if ((classname == null) || (classname == string.Empty))
     {
         this.classname = this.GetWsClassName(Url);
     }
     else
     {
         this.classname = classname;
     }
     try
     {
         Stream stream = new WebClient().OpenRead(Url + "?WSDL");
         ServiceDescription serviceDescription = ServiceDescription.Read(stream);
         ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
         importer.AddServiceDescription(serviceDescription, "", "");
         CodeNamespace namespace2 = new CodeNamespace([email protected]);
         stream.Close();
         CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
         codeCompileUnit.Namespaces.Add(namespace2);
         importer.Import(namespace2, codeCompileUnit);
         ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();
         CompilerParameters options = new CompilerParameters();
         options.GenerateExecutable = false;
         options.GenerateInMemory = true;
         options.ReferencedAssemblies.Add("System.dll");
         options.ReferencedAssemblies.Add("System.XML.dll");
         options.ReferencedAssemblies.Add("System.Web.Services.dll");
         options.ReferencedAssemblies.Add("System.Data.dll");
         CompilerResults results = compiler.CompileAssemblyFromDom(options, codeCompileUnit);
         if (results.Errors.HasErrors)
         {
             StringBuilder builder = new StringBuilder();
             foreach (CompilerError error in results.Errors)
             {
                 builder.Append(error.ToString());
                 builder.Append(Environment.NewLine);
             }
             throw new Exception(builder.ToString());
         }
         this.assembly = results.CompiledAssembly;
     }
     catch (Exception exception)
     {
         throw new Exception(exception.InnerException.Message, new Exception(exception.InnerException.StackTrace));
     }
 }
开发者ID:suizhikuo,项目名称:KYCMS,代码行数:47,代码来源:WebServiceHelper.cs

示例2: UploadRecordToS3

        private void UploadRecordToS3(string callId, string parentCallId, string recordUrl)
        {
            try
            {
                Thread.Sleep(10000);
                CoreContext.TenantManager.SetCurrentTenant(Tenant);
                var stream = new WebClient().OpenRead(recordUrl);
                var storage = StorageFactory.GetStorage(Tenant.TenantId.ToString(CultureInfo.InvariantCulture), "crm");
                var newRecordUri = storage.Save(recordUrl.Split('/').Last() + ".wav", stream.GetBuffered());
                if (stream != null)
                    stream.Close();

                SaveOrUpdateCallHistory(callId, parentCallId, recordUrl: newRecordUri.AbsoluteUri);
            }
            catch (Exception e)
            {
                Log.ErrorFormat("UploadRecord: StackTrace:{0}, Message: {1}", e.StackTrace, e.Message);
            }
        }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:19,代码来源:ApiHelper.cs

示例3: SaveComplaint

 public void SaveComplaint()
 {
     try
     {
     WebClient client = new WebClient();
     client.Headers["Content-type"] = "application/json";
         ConsoleTest.Models.complaintItem temp = new ConsoleTest.Models.complaintItem();
         //temp.complaintId = complaint.complaintId;
         temp.userId = 1;
         temp.title = "Rubbish Test";
         temp.details = "Test Rubbish";
         temp.numLikes = 2;
         temp.numComments = 1;
         temp.picture = "zascac";
         temp.complaintDate = DateTime.Now;
         temp.location = "dasdas";
         temp.latitude = (float)0.323;
         temp.longitude = (float)32.44;
         temp.category = "pothole";
         temp.complaintStatus = "Solved";
         temp.date = DateTime.Now;
         temp.isAnonymous = 1;
         string path = @"C:\Users\Banka\Desktop\images.jpg";
         FileStream fs=new FileStream(path,FileMode.Open);
         byte[] PhotoBytes = new byte[fs.Length];
         fs.Read(PhotoBytes, 0, PhotoBytes.Length);
         temp.ImageByte = PhotoBytes;
         MemoryStream stream = new MemoryStream();
         DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ConsoleTest.Models.complaintItem));
         serializer.WriteObject(stream, temp);
         byte[] data = client.UploadData("http://127.0.0.1/Core.svc/SaveComplaint", "POST", stream.ToArray());
         stream = new MemoryStream(data);
         serializer = new DataContractJsonSerializer(typeof(int));
         int result = (int)serializer.ReadObject(stream);
         Console.WriteLine("Save User Result : " + result);
         logger.warning("Exit TestConnection Method");
         Console.ReadLine();
     }
     catch (FaultException<ConsoleTest.CoreService.Bug> Fex)
     {
         logger.error("ErrorMessage::" + Fex.Detail.ErrorMessage + Environment.NewLine);
         logger.error("ErrorDetails::" + Environment.NewLine + Fex.Detail.ErrorDetails);
         Console.ReadLine();
     }
     finally
     {
         if (null != client)
         {
             client.Close();
         }
     }
 }
开发者ID:harjoben,项目名称:socialCopsDev,代码行数:52,代码来源:Program.cs

示例4: SaveUser

        //public void TestConnection()
        //{
        //    logger.warning("Enter TestConnection Method");
        //    try
        //    {
        //        client = new CoreClient();
        //        TestConnectionRequest request = new TestConnectionRequest();
        //        TestConnectionResponse response;
        //        response = client.TestConnection(request);
        //        Console.WriteLine("Testing Connection Result : " + response.TestConnectionResult);
        //        logger.warning("Exit TestConnection Method");
        //        Console.ReadLine();
        //    }
        //    catch (FaultException<ConsoleTest.CoreService.Bug> Fex)
        //    {
        //        logger.error("ErrorMessage::" + Fex.Detail.ErrorMessage + Environment.NewLine);
        //        logger.error("ErrorDetails::" + Environment.NewLine + Fex.Detail.ErrorDetails);
        //        Console.ReadLine();
        //    }
        //    finally
        //    {
        //        if (null != client)
        //        {
        //            client.Close();
        //        }
        //    }
        //}
        public void SaveUser()
        {
            logger.warning("Enter TestConnection Method");
            try
            {
                WebClient client = new WebClient();
                client.Headers["Content-type"] = "application/json";
                ConsoleTest.Models.userItem item = new ConsoleTest.Models.userItem();
                item.userName = "Varun Banka";
                item.userAddress = "scdscscsdac";
                item.email = "[email protected]";
                item.date = DateTime.Now;

                MemoryStream stream = new MemoryStream();
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ConsoleTest.Models.userItem));
                serializer.WriteObject(stream, item);
                byte[] data = client.UploadData("http://127.0.0.1/Core.svc/SaveUser", "POST", stream.ToArray());
                stream = new MemoryStream(data);
                serializer = new DataContractJsonSerializer(typeof(int));
                int result = (int)serializer.ReadObject(stream);
                Console.WriteLine("Save User Result : " + result);
                logger.warning("Exit TestConnection Method");
                Console.ReadLine();
            }
            catch (FaultException<ConsoleTest.CoreService.Bug> Fex)
            {
                logger.error("ErrorMessage::" + Fex.Detail.ErrorMessage + Environment.NewLine);
                logger.error("ErrorDetails::" + Environment.NewLine + Fex.Detail.ErrorDetails);
                Console.ReadLine();
            }
            finally
            {
                if (null != client)
                {
                    client.Close();
                }
            }
        }
开发者ID:harjoben,项目名称:socialCopsDev,代码行数:65,代码来源:Program.cs

示例5: GetRegionMap

 /// <summary>
 /// Gets the region map.
 /// </summary>
 /// <param name="url">URL.</param>
 /// <returns></returns>
 private Image GetRegionMap(Uri url)
 {
     Image map = Cache.Instance.Get(url) as Image;
     if (map == null)
         try
         {
             Stream ImageStream = new WebClient().OpenRead(url.AbsoluteUri);
             map = Image.FromStream(ImageStream);
             ImageStream.Close();
             Cache.Instance.Insert(url, map, CacheItemLifetime.Permanent);
         }
         catch {
             map = GetWeatherIcon("NOCONNECTION");
         }
     return map;
 }
开发者ID:cihypan,项目名称:biold,代码行数:21,代码来源:WeatherPlugin.cs


注:本文中的System.Net.WebClient.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。