Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            AppDomain.CreateDomain("Server").DoCallBack(delegate
            {
                ServiceHost host = new ServiceHost(typeof(UpLoadService),
                                                   new Uri("http://localhost:1630/UpLoadService.svc"));

                BasicHttpBinding binding       = new BasicHttpBinding();
                binding.TransferMode           = TransferMode.Streamed;
                binding.MaxReceivedMessageSize = 67108864;

                host.AddServiceEndpoint(typeof(IUpLoadService), binding, "");

                host.Open();
            });

            BasicHttpBinding binding2 = new BasicHttpBinding();

            binding2.TransferMode = TransferMode.Streamed;

            IUpLoadService channel = ChannelFactory <IUpLoadService> .CreateChannel(binding2,
                                                                                    new EndpointAddress("http://localhost:1630/UpLoadService.svc"));

            using (channel as IDisposable)
            {
                FileUploadMessage file = new FileUploadMessage();
                file.SavePath = "ppp";
                file.FileName = "safs.bak";
                file.FileData = new FileStream("D:/work/C#/lll.bak", FileMode.Open);

                channel.UploadFile(file);

                file.FileData.Close();
            }
        }
Ejemplo n.º 2
0
        private void btnInvokeByHand_Click(object sender, EventArgs e)
        {
            string fileName = SelectFile();

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            this.Cursor = Cursors.WaitCursor;
            FileStream stream = File.OpenRead(fileName);
            var        req    = new FileUploadMessage(fileName.Substring(fileName.LastIndexOf('\\') + 1), "", stream);

            BasicHttpBinding binding = new BasicHttpBinding();

            binding.TransferMode           = TransferMode.Streamed;
            binding.MessageEncoding        = WSMessageEncoding.Mtom;
            binding.MaxReceivedMessageSize = 9223372036854775807;
            binding.SendTimeout            = new TimeSpan(0, 0, 10, 0); // 设置十分钟超时

            IUpLoadService channel = ChannelFactory <IUpLoadService> .CreateChannel(binding,
                                                                                    new EndpointAddress("http://localhost:62805/UpLoadService.svc"));

            using (channel as IDisposable)
            {
                channel.UploadFile(req);
                stream.Close();
                this.Cursor = Cursors.Default;
                MessageBox.Show("文件上传到服务器成功", "上传WCF", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }