private void PublishPackage(PublishState state) { var url = new Uri(String.Format(CultureInfo.InvariantCulture, "{0}/{1}", _baseGalleryServerUrl, PublishPackageService)); using (Stream requestStream = new MemoryStream()) { var data = new PublishData { Key = state.PublishKey, Id = state.PackageMetadata.Id, Version = state.PackageMetadata.Version.ToString() }; var jsonSerializer = new DataContractJsonSerializer(typeof(PublishData)); jsonSerializer.WriteObject(requestStream, data); requestStream.Seek(0, SeekOrigin.Begin); WebClient client = new WebClient(); client.Proxy = _cachedProxy; client.Headers[HttpRequestHeader.ContentType] = "application/json"; client.Headers[HttpRequestHeader.UserAgent] = _userAgent; client.UploadProgressChanged += OnUploadProgressChanged; client.UploadDataCompleted += OnPublishPackageCompleted; client.UploadDataAsync(url, "POST", requestStream.ReadAllBytes(), state); } }