none
Error while using WCF Test Client RRS feed

  • Question

  • Hello,

    I m receiving the following error while using the WCF Test Client and 

    Object reference not set to an instance of an object.
    
    Server stack trace: 
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at IApplicationCategorieService.GetAllApplicationsCategories()
       at ApplicationCategorieServiceClient.GetAllApplicationsCategories()

    This is what my Web.config looks like

      <system.serviceModel>
        <services>
          <service name="intranet.business.managers.ApplicationsCategoriesManager" behaviorConfiguration="metadataBehavior">
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://someaddress:808" />
              </baseAddresses>
            </host>
            <endpoint address="UsersService" binding="netTcpBinding" contract="intranet.contracts.IUserService"/>
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
          </service>
    
        </services>
    
        <bindings>
          <netTcpBinding>
            <binding>
              <security mode="Transport">
                <transport protectionLevel="EncryptAndSign" 
                           clientCredentialType="Windows" />
              </security>
            </binding>
          </netTcpBinding>
        </bindings>
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="metadataBehavior">
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      </system.serviceModel>

    Any Ideas?

    Sunday, October 20, 2013 6:23 AM

Answers

  • First I wanted to thank Miguel Castro for his help. I had totally forgotten about building the MEF container, as a result my _DataRepositoryFactory was always null.

    I added a global.asax file and on application start Init my MEF container.

    All of my services are happy now.

    _OUsmane

     
    • Marked as answer by DofLeFou Monday, October 21, 2013 8:05 PM
    Monday, October 21, 2013 8:05 PM

All replies

  • <copied>

    Object reference not set to an instance of an object.

    <end>

    You have a programming problem with your code, and the test harness is just exposing it.

    There must be an instance of the object in memory so that the object can be used.  It's usually done with the "NEW" statement at some point.  

    DofLeFou theobj  = new DofLeFou()

    theobj is a instance of DofLeFou,  and the instance of the object has memory and it exist.

    string name = theobj.name   ----> no problem here

    ================================

    DofLeFou theobj

    string name = theobj.name   ----> BOOM! The program is going to blow up with Object reference not set to an instance of an object.

    It blows up, because the code references an object. But the object has no instance in memory and it doesn't exist.

    It's just a simple example of what that error message means.

    It doesn't matter if it's Java or .NET, because the principles of Object Oriented Programming are the same.

    http://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/

    Sunday, October 20, 2013 7:41 AM
  • Can you please provide your code?


    Thanks Subhendu DE - DotNet Artisan If a post answers your question, please click Mark As Answer on that post. If you find a post helpful, please click Vote as Helpful

    Sunday, October 20, 2013 3:07 PM
  • DE,

    This what my Service code look like

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,
                         ConcurrencyMode = ConcurrencyMode.Multiple,
                         ReleaseServiceInstanceOnTransactionComplete = false)]
        public class ApplicationsManager : ManagerBase, IApplicationService
        {
            public ApplicationsManager()
            {
            }
    
            public ApplicationsManager(IDataRepositoryFactory dataRepositoryFactory)
            {
                _DataRepositoryFactory = dataRepositoryFactory;
            }
    
            public ApplicationsManager(IBusinessEngineFactory businessEngineFactory)
            {
                _BusinessEngineFactory = businessEngineFactory;
            }
    
            public ApplicationsManager(IDataRepositoryFactory dataRepositoryFactory, IBusinessEngineFactory businessEngineFactory)
            {
                _DataRepositoryFactory = dataRepositoryFactory;
                _BusinessEngineFactory = businessEngineFactory;
            }
    
            [Import]
            IDataRepositoryFactory _DataRepositoryFactory;
    
            [Import]
            IBusinessEngineFactory _BusinessEngineFactory;
    
            #region IApplicationService operations
    
            [OperationBehavior(TransactionScopeRequired = true)]
            [PrincipalPermission(SecurityAction.Demand, Role = Security.IntranetRootUsers)]
            public Applications AddApplication(Applications application)
            {
                return ExecuteFaultHandledOperation(() =>
                {
                    IApplicationsRepository applicationsRepository = _DataRepositoryFactory.GetDataRepository<IApplicationsRepository>();
    
                    Applications addedEntity = null;
    
                    if (application.ApplicationsId == 0)
                        addedEntity = applicationsRepository.Add(application);
    
                    return addedEntity;
                });
            }
    
                   #endregion
        }

    And my Service on contract

    [ServiceContract(ProtectionLevel=ProtectionLevel.EncryptAndSign)]
        public interface IApplicationService
        {
            [OperationContract]
            [TransactionFlow(TransactionFlowOption.Allowed)]
            Applications AddApplication(Applications application);
    
        }

    Thank you
    Sunday, October 20, 2013 4:40 PM
  • I did some further digging. It appears that the exception is thrown only with the following line

     IApplicationsRepository applicationsRepository = _DataRepositoryFactory.GetDataRepository<IApplicationsRepository>();

    Sunday, October 20, 2013 5:10 PM
  • I guess I need to figure out how to use MEF for instantiating the dependencies in an application that has several WCF services hosted in IIS.
    Sunday, October 20, 2013 6:04 PM
  • First I wanted to thank Miguel Castro for his help. I had totally forgotten about building the MEF container, as a result my _DataRepositoryFactory was always null.

    I added a global.asax file and on application start Init my MEF container.

    All of my services are happy now.

    _OUsmane

     
    • Marked as answer by DofLeFou Monday, October 21, 2013 8:05 PM
    Monday, October 21, 2013 8:05 PM