• 大小: 0.09M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2020-12-26
  • 语言: C#
  • 标签: WCF  上传  进度条  文件  

资源简介

部分win7/win8用户 运行时报错 可能是 权限问题,所以运行项目的时候 要右键>>以管理员身份运行

部分用户 运行该项目的时候 可能提示:协定需要双工 但是绑定 NetTcpBinding 不支持

这是只需要将host项目app.config中协议部分 改为wsDualHttpBinding 即可,如下代码:


      <service name="WcfUploadServiceLib.UpLoadService">
        <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="DualHttpBinding"
          contract="WcfUploadServiceLib.IUpLoadService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8890/WcfUploadService/" />
            <add baseAddress="net.tcp://localhost:8888/WcfUploadService/" />
          </baseAddresses>
        </host>
      </service>



另外使用wcf时,最好不要使用 using 因为使用using会屏蔽掉很多错误,误导用户,参考链接:http://www.codeproject.com/Tips/197531/Do-not-use-using-for-WCF-Clients

相关代码改为:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.ServiceModel;

namespace WcfUploadServiceHost
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {

                var host = new ServiceHost(typeof (WcfUploadServiceLib.UpLoadService));
                host.Open();
                Console.WriteLine("Server is opened...");
                Console.Read();

                //using (var host = new ServiceHost(typeof(WcfUploadServiceLib.UpLoadService)))
                //{
                //    host.Open();
                //    Console.WriteLine("Server is opened...");
                //    Console.Read();
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.Read();
            }
        }
    }
}


资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WcfUploadClient
{
    public class CallbackImpl : WcfUploadSvc.IUpLoadServiceCallback
    {
        public event Action OnUploadProcess;

        public void OnProcess(WcfUploadSvc.UpLoadProcessEventArgs args)
        {
            if (OnUploadProcess != null)
                OnUploadProcess(args);
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-09-26 00:08  WcfUploadService\
     目录           0  2011-09-26 00:08  WcfUploadService\WcfUploadClient\
     文件        1748  2011-06-07 14:37  WcfUploadService\WcfUploadClient\app.config
     目录           0  2012-09-06 23:43  WcfUploadService\WcfUploadClient\bin\
     文件         473  2011-01-23 23:05  WcfUploadService\WcfUploadClient\CallbackImpl.cs
     文件        2347  2011-01-24 00:12  WcfUploadService\WcfUploadClient\Form1.cs
     文件        5127  2011-01-23 23:57  WcfUploadService\WcfUploadClient\Form1.Designer.cs
     文件        6020  2011-01-23 23:57  WcfUploadService\WcfUploadClient\Form1.resx
     目录           0  2011-09-26 00:08  WcfUploadService\WcfUploadClient\obj\
     目录           0  2011-09-26 00:08  WcfUploadService\WcfUploadClient\obj\x86\
     目录           0  2011-09-26 00:08  WcfUploadService\WcfUploadClient\obj\x86\Debug\
     文件        4440  2011-01-24 21:20  WcfUploadService\WcfUploadClient\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7753  2011-06-07 14:37  WcfUploadService\WcfUploadClient\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         678  2011-06-07 14:35  WcfUploadService\WcfUploadClient\obj\x86\Debug\GenerateResource.read.1.tlog
     文件        1618  2011-06-07 14:35  WcfUploadService\WcfUploadClient\obj\x86\Debug\GenerateResource.write.1.tlog
     目录           0  2011-09-26 00:08  WcfUploadService\WcfUploadClient\obj\x86\Debug\TempPE\
     文件        8192  2011-01-24 00:12  WcfUploadService\WcfUploadClient\obj\x86\Debug\TempPE\Service References.WcfUploadSvc.Reference.cs.dll
     文件        3102  2011-06-07 14:35  WcfUploadService\WcfUploadClient\obj\x86\Debug\WcfUploadClient.csproj.FileListAbsolute.txt
     文件       14848  2011-06-07 14:35  WcfUploadService\WcfUploadClient\obj\x86\Debug\WcfUploadClient.exe
     文件         180  2011-06-07 14:35  WcfUploadService\WcfUploadClient\obj\x86\Debug\WcfUploadClient.Form1.resources
     文件       40448  2011-06-07 14:35  WcfUploadService\WcfUploadClient\obj\x86\Debug\WcfUploadClient.pdb
     文件         180  2011-06-07 14:35  WcfUploadService\WcfUploadClient\obj\x86\Debug\WcfUploadClient.Properties.Resources.resources
     文件         507  2010-12-30 12:53  WcfUploadService\WcfUploadClient\Program.cs
     目录           0  2011-09-26 00:08  WcfUploadService\WcfUploadClient\Properties\
     文件        1442  2010-12-30 12:53  WcfUploadService\WcfUploadClient\Properties\AssemblyInfo.cs
     文件        2856  2010-12-30 12:53  WcfUploadService\WcfUploadClient\Properties\Resources.Designer.cs
     文件        5612  2010-12-30 12:53  WcfUploadService\WcfUploadClient\Properties\Resources.resx
     文件        1098  2010-12-30 12:53  WcfUploadService\WcfUploadClient\Properties\Settings.Designer.cs
     文件         249  2010-12-30 12:53  WcfUploadService\WcfUploadClient\Properties\Settings.settings
     目录           0  2011-09-26 00:08  WcfUploadService\WcfUploadClient\Service References\
     目录           0  2011-09-26 00:08  WcfUploadService\WcfUploadClient\Service References\WcfUploadSvc\
............此处省略55个文件信息

评论

共有 条评论