并发调用时WCF服务的性能

时间:2018-11-21 04:31:38

标签: c# wcf iis wshttpbinding

以下服务通过WSHTTPBinding托管在IIS中 服务代码

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single, AddressFilterMode = AddressFilterMode.Any)]
   public class Service1 : IService1
   {}
  [OperationBehavior(TransactionScopeRequired = true)]
  public File_Data CopyFile(File_Data oFileData)
  {}

呼叫服务

    _binding = new WSHttpBinding();
                _binding.SendTimeout = new TimeSpan(0, 30, 0);
                _binding.ReceiveTimeout = new TimeSpan(0, 30, 0);
                _binding.OpenTimeout = new TimeSpan(0, 30, 0);
                _binding.CloseTimeout = new TimeSpan(0, 30, 0);
                _binding.MaxBufferPoolSize = Int32.MaxValue;
                _binding.MaxReceivedMessageSize = Int32.MaxValue;
                _binding.ReaderQuotas.MaxDepth = Int32.MaxValue;
                _binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                _binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
                _binding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue;
                _binding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;
                _binding.Security.Mode = SecurityMode.None;
                _binding.TransactionFlow = true;
                //_binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;



                _endpoint = new EndpointAddress(VirtualDir+ "\\" + "Service1.svc");



 public File_Data Copy_File(File_Data objFile_Data)
        {
            ChannelFactory<IService1> Channel = null;
            try
            {
                Channel = new ChannelFactory<IService1>(_binding, _endpoint);
                IService1 proxy = Channel.CreateChannel();
                objFile_Data = proxy.CopyFile(objFile_Data);
            }
            catch (Exception ex)
            {
                msgError = ex.Message;
            }
            finally
            {
                if (Channel != null)
                {
                    Channel.Close();
                    Channel.Abort();
                }
                Channel = null;`
            }
            return objFile_Data;
        }

从多个客户端调用服务时,需要花费一些时间来完成操作 我如何配置服务行为以改善服务性能

0 个答案:

没有答案