我有一个wcf服务。宿主是这么写的,前面是连接oracle数据库            string ConnectionString = "Data Source=SDETEST;user=sde;password=sde;Pooling=true;Min Pool Size=4;Max Pool Size=1000";
            OracleConnection conn = new OracleConnection(ConnectionString);
            conn.Open();
            RestServiceImpl rest = new RestServiceImpl(conn);
            WebServiceHost host = new WebServiceHost(rest);
            host.Open();
            Console.WriteLine("Service is running");
            Console.ReadLine();
            host.Close();;之前服务里这样用[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
客户端调用没问题。可是我要让数据库能够并发访问,先是将oncurrencyMode = ConcurrencyMode.Single改为Multiple,可是本身service并发明显不行。于是就将InstanceContextMode = InstanceContextMode.Single改为percall,可是改了以后host.open()提示出错了,错误内容是:
    “In order to use one of the ServiceHost constructors that takes a service instance, the InstanceContextMode of the service must be set to InstanceContextMode.Single.  This can be configured via the ServiceBehaviorAttribute.  Otherwise, please consider using the ServiceHost constructors that take a Type argument.”
     请教各位怎么改才行。。或者给我个新思路,最终目的是用rest能并发访问数据库。

解决方案 »

  1.   

    WebServiceHost host = new WebServiceHost(rest);有这么个东西么?CaptureWCFService 是我写的WCF实现类的类名。我用的Console做宿主。
    你开启数据库为什么要放在Host不放在WCF里呢?
    using (ServiceHost host = new ServiceHost(typeof(CaptureWCFService)))
    {
        host.Open();
    }
      

  2.   

    超级新手表示还没毕业- - 刚刚学习表示不懂。。我是觉得如果数据库连接写在wcf里的话不是每次一个实例都会连接一次数据库,还是我理解的不对主要目的就是要增加并发量
      

  3.   

    .NET有先进的连接缓存关闭,只要你记得用完连接后立刻关闭,那么下次打开新的数据库连接其实是使用上次使用过的缓存连接,不会开很多连接的,而并发本身需要多个数据库连接才可能实现,如果你只提供一个连接,永远并发不起来。
      

  4.   

    “.NET有先进的连接缓存关闭”,改为“.NET有先进的连接缓存管理