本文整理汇总了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));
}
}
示例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);
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}