2015-12-31 22 views
1

由於WCF中的異常,處於showstopper狀態的Im。問題是我在WCF的Windows服務中隨機獲取這個異常。現在,因爲我無法調試生產服務器,所以我使用log4net進行日誌記錄。這個例外在時間和功能上是隨機的。它幾乎在每天發生幾乎400到1000分貝的條目。現在這裏是我的代理類代碼,用於檢查客戶端打開狀態。ChannelFactory`1 [BLLService],在處於打開狀態時無法修改

public static BLLServiceClient bLLServiceClient 
     { 
      get 
      { 
       if (_bLLServiceClient == null || _bLLServiceClient.State != CommunicationState.Opened) 
       { 
    _bLLServiceClient = new BLLServiceClient(Common.GetBinding(_settings.BLLServiceBinding), new EndpointAddress(_settings.BLLServiceAddress));       
    _bLLServiceClient.Open(); 
       }     
       return _bLLServiceClient; 
      } 
      set 
      { 
       _bLLServiceClient = value; 
      } 
     } 

這意味着如果客戶是不是在打開狀態,然後打開它,否則返回客戶端

唯一的例外是

SetSiteDataStatusInDatabase: ____ The communication object, System.ServiceModel.ChannelFactory`1[BLLService], cannot be modified while it is in the Opening state. 
System.ServiceModel 
    at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable() 
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) 
    at System.ServiceModel.ChannelFactory.EnsureOpened() 
    at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via) 
    at System.ServiceModel.ChannelFactory`1.CreateChannel() 
    at System.ServiceModel.ClientBase`1.CreateChannel() 
    at System.ServiceModel.ClientBase`1.CreateChannelInternal() 
    at System.ServiceModel.ClientBase`1.get_Channel() 
    at BLLServiceClient.UpdateData(SiteData eSiteData) 
    at DataHelper.SetSiteDataStatusInDatabase(SiteData oSiteData, CurrentTaskStatus newStatus) 
Void ThrowIfDisposedOrImmutable() 
System.Collections.ListDictionaryInternal 
Full Exception.... 
System.InvalidOperationException: The communication object, System.ServiceModel.ChannelFactory`1[ BLLService], cannot be modified while it is in the Opening state. 
    at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable() 
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) 
    at System.ServiceModel.ChannelFactory.EnsureOpened() 
    at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via) 
    at System.ServiceModel.ChannelFactory`1.CreateChannel() 
    at System.ServiceModel.ClientBase`1.CreateChannel() 
    at System.ServiceModel.ClientBase`1.CreateChannelInternal() 
    at System.ServiceModel.ClientBase`1.get_Channel() 
    at Proxy.BLLService.BLLServiceClient.UpdateData(SiteData eSiteData) 
    at DataHelper.SetSiteDataStatusInDatabase(SiteData oSiteData, CurrentTaskStatus newStatus) 

試圖尋找,但沒找到修改的異常類型

edite: 使用@Agalo回答後,現在異常已更改爲

Exception of type 'System.OutOfMemoryException' was thrown. 
System 
    at System.Uri.CreateHelper(String uriString, Boolean dontEscape, UriKind uriKind, UriFormatException& e) 
    at System.Uri.TryCreate(String uriString, UriKind uriKind, Uri& result) 
    at System.ServiceModel.Description.NamingHelper.CheckUriParameter(String ns, String paramName) 
    at System.ServiceModel.Description.MessagePartDescription..ctor(String name, String ns) 
    at System.ServiceModel.Description.TypeLoader.CreateParameterPartDescription(XmlName defaultName, String defaultNS, Int32 index, ICustomAttributeProvider attrProvider, Type type) 
    at System.ServiceModel.Description.TypeLoader.CreateParameterMessageDescription(ParameterInfo[] parameters, Type returnType, ICustomAttributeProvider returnAttrProvider, XmlName returnValueName, String methodName, String defaultNS, String action, XmlName wrapperName, String wrapperNamespace, MessageDirection direction) 
    at System.ServiceModel.Description.TypeLoader.CreateMessageDescription(MethodInfo methodInfo, Boolean isAsync, Boolean isTask, Type taskTResult, XmlName returnValueName, String defaultNS, String action, XmlName wrapperName, String wrapperNamespace, MessageDirection direction) 
    at System.ServiceModel.Description.TypeLoader.CreateOperationDescription(ContractDescription contractDescription, MethodInfo methodInfo, MessageDirection direction, ContractReflectionInfo reflectionInfo, ContractDescription declaringContract) 
    at System.ServiceModel.Description.TypeLoader.CreateOperationDescriptions(ContractDescription contractDescription, ContractReflectionInfo reflectionInfo, Type contractToGetMethodsFrom, ContractDescription declaringContract, MessageDirection direction) 
    at System.ServiceModel.Description.TypeLoader.CreateContractDescription(ServiceContractAttribute contractAttr, Type contractType, Type serviceType, ContractReflectionInfo& reflectionInfo, Object serviceImplementation) 
    at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation) 
    at System.ServiceModel.ChannelFactory`1.CreateDescription() 
    at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address) 
    at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress) 
    at System.ServiceModel.ClientBase`1..ctor(Binding binding, EndpointAddress remoteAddress) 
    at BLLServiceClient..ctor(Binding binding, EndpointAddress remoteAddress) 
    at ServiceClients.get_bLLServiceClient() 
    at SiteDataHelper.get_bLLServiceClient() 
    at SiteDataHelper.FetchFilesListToDownload(Int32 siteDataId) 
System.Uri CreateHelper(System.String, Boolean, System.UriKind, System.UriFormatException ByRef) 
System.Collections.ListDictionaryInternal 
Full Exception.... 
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. 
    at System.Uri.CreateHelper(String uriString, Boolean dontEscape, UriKind uriKind, UriFormatException& e) 
    at System.Uri.TryCreate(String uriString, UriKind uriKind, Uri& result) 
    at System.ServiceModel.Description.NamingHelper.CheckUriParameter(String ns, String paramName) 
    at System.ServiceModel.Description.MessagePartDescription..ctor(String name, String ns) 
    at System.ServiceModel.Description.TypeLoader.CreateParameterPartDescription(XmlName defaultName, String defaultNS, Int32 index, ICustomAttributeProvider attrProvider, Type type) 
    at System.ServiceModel.Description.TypeLoader.CreateParameterMessageDescription(ParameterInfo[] parameters, Type returnType, ICustomAttributeProvider returnAttrProvider, XmlName returnValueName, String methodName, String defaultNS, String action, XmlName wrapperName, String wrapperNamespace, MessageDirection direction) 
    at System.ServiceModel.Description.TypeLoader.CreateMessageDescription(MethodInfo methodInfo, Boolean isAsync, Boolean isTask, Type taskTResult, XmlName returnValueName, String defaultNS, String action, XmlName wrapperName, String wrapperNamespace, MessageDirection direction) 
    at System.ServiceModel.Description.TypeLoader.CreateOperationDescription(ContractDescription contractDescription, MethodInfo methodInfo, MessageDirection direction, ContractReflectionInfo reflectionInfo, ContractDescription declaringContract) 
    at System.ServiceModel.Description.TypeLoader.CreateOperationDescriptions(ContractDescription contractDescription, ContractReflectionInfo reflectionInfo, Type contractToGetMethodsFrom, ContractDescription declaringContract, MessageDirection direction) 
    at System.ServiceModel.Description.TypeLoader.CreateContractDescription(ServiceContractAttribute contractAttr, Type contractType, Type serviceType, ContractReflectionInfo& reflectionInfo, Object serviceImplementation) 
    at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation) 
    at System.ServiceModel.ChannelFactory`1.CreateDescription() 
    at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address) 
    at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress) 
    at System.ServiceModel.ClientBase`1..ctor(Binding binding, EndpointAddress remoteAddress) 
    at BLLServiceClient..ctor(Binding binding, EndpointAddress remoteAddress) 
    at ServiceClients.get_bLLServiceClient() 
    at SiteDataHelper.get_bLLServiceClient() 
    at SiteDataHelper.FetchFilesListToDownload(Int32 siteDataId) 

回答

2

你可以試試下面任

  1. 列出你的具體情況2級的解決方案,有可能的是,我nner的ChannelFactory已經在創建/打開狀態,當你試圖打開代理服務器正在調用通道工廠的Open方法,該方法正在拋出無效操作異常。要解決此問題,您需要在打開代理之前檢查Channel of Channel Factory狀態。因此,您需要驗證渠道工廠是否已經創建,那麼您無需再次打開代理。

    _bLLServiceClient.ChannelFactory.State != CommunicationState.Created 
    

修改函數代碼

public static BLLServiceClient bLLServiceClient 
     { 
      get 
      { 
       if (_bLLServiceClient == null || _bLLServiceClient.State != CommunicationState.Opened 
        || _bLLServiceClient.ChannelFactory.State != CommunicationState.Created) 
       { 
        _bLLServiceClient = new BLLServiceClient(Common.GetBinding(_settings.BLLServiceBinding), new EndpointAddress(_settings.BLLServiceAddress)); 
        _bLLServiceClient.Open(); 
       } 
       return _bLLServiceClient; 
      } 
      set 
      { 
       _bLLServiceClient = value; 
      } 
     } 
  • 一種溶液的,是避免使用打開方法。當您調用任何WCF服務方法打開調用將在內部進行。所以它會被自動調用。
  • +0

    有一件事我錯過的是,我打開窗戶服務的5個實例被訪問相同的對象,我會試圖鎖定對象 – skhurams

    +0

    仍然會收到你嘗試哪種解決方案相同的異常 – skhurams

    +0

    ?兩者? – Agalo

    相關問題