Exemple #1
0
 public static void Upload(byte[] bytes)
 {
     string serviceAddress = string.Format("http://{0}:{1}/FileCopy/", "eric-pc", "8001");
     ChannelFactory<ICopyService> myChannelFactory = new ChannelFactory<ICopyService>(new BasicHttpBinding(), new EndpointAddress(serviceAddress));
     var copyServiceClient = new CopyServiceClient(new BasicHttpBinding(), new EndpointAddress(serviceAddress));
     copyServiceClient.CopyBytesAsync("levels.dat", bytes);
 }
        public void BeginUpload()
        {
            if (IsUploading)
                return;
            string serviceAddress = string.Format("http://{0}:{1}/FileCopy/", this.MachineName, TargetPort);
            ChannelFactory<ICopyService> myChannelFactory = new ChannelFactory<ICopyService>(new BasicHttpBinding(), new EndpointAddress(serviceAddress));

            //_copyServiceClient = myChannelFactory.CreateChannel(new EndpointAddress(serviceAddress));

            var copyServiceClient = new CopyServiceClient(new BasicHttpBinding(), new EndpointAddress(serviceAddress));

            if(UseBinary)
            {
                var encoder = System.Text.UnicodeEncoding.Unicode;
                var byteList = encoder.GetBytes(Content);
                copyServiceClient.CopyBytesCompleted += new EventHandler<AsyncCompletedEventArgs>(copyServiceClient_CopyBytesCompleted);
                copyServiceClient.CopyBytesAsync(FileName, byteList);
            }
            else
            {
                IsUploading = true;
                copyServiceClient.CopyStringCompleted += new EventHandler<AsyncCompletedEventArgs>(copyServiceClient_CopyStringCompleted);
                copyServiceClient.CopyStringAsync(FileName,Content);
            }
        }