ServiceMissingException

Topics: Web Client Software Factory
Jul 26, 2007 at 8:05 AM
I am fairly new to the WCSF and am completely stuck. I have a project that follows pretty closely the reference implementation in terms of structure, and I have a ServiceProxies module that contains the entity translation and web references to the web services I am using. In my Companies module, I can't get past the Load statement -- I get a ServiceMissingException. I can't figure out where I am going wrong here, and any help is much appreciated. What has me really perplexed is that the service it is referring to is within the module.

The message is: ServiceMissingException: Service xxx.WebClient.Modules.Companies.Services.ICompanyServiceAgent is not available in the current context.

Microsoft.Practices.CompositeWeb.Collections.ServiceCollection.Get(Type serviceType, Boolean ensureExists) +291
Microsoft.Practices.CompositeWeb.Collections.ServiceCollection.Get(Type serviceType, Boolean ensureExists) +237
Microsoft.Practices.CompositeWeb.ServiceDependencyParameter.GetValue(IBuilderContext context) +142
Microsoft.Practices.ObjectBuilder.ConstructorPolicy.GetParameters(IBuilderContext context, Type type, String id, ConstructorInfo constructor) +102
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.InitializeObject(IBuilderContext context, Object existing, String id, ICreationPolicy policy) +117
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUpNewObject(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +208
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +51
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +171
Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +322
Microsoft.Practices.ObjectBuilder.CreationParameter.GetValue(IBuilderContext context) +31
Microsoft.Practices.ObjectBuilder.ConstructorPolicy.GetParameters(IBuilderContext context, Type type, String id, ConstructorInfo constructor) +102
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.InitializeObject(IBuilderContext context, Object existing, String id, ICreationPolicy policy) +117
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUpNewObject(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +208
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +51
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +171
Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +322
Microsoft.Practices.ObjectBuilder.CreationParameter.GetValue(IBuilderContext context) +31
Microsoft.Practices.ObjectBuilder.PropertySetterInfo.GetValue(IBuilderContext context, Type type, String id, PropertyInfo propInfo) +10
Microsoft.Practices.ObjectBuilder.PropertySetterStrategy.InjectProperties(IBuilderContext context, Object obj, String id) +259
Microsoft.Practices.ObjectBuilder.PropertySetterStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +29
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +68
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +171
Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +322
Microsoft.Practices.ObjectBuilder.WCSFExtensions.WCSFBuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +151
Microsoft.Practices.CompositeWeb.CompositionContainer.BuildItem(IBuilder`1 builder, IReadWriteLocator locator, Object item) +256
Microsoft.Practices.CompositeWeb.WebClientApplication.InnerPreRequestHandlerExecute(IHttpContext context) +92
Microsoft.Practices.CompositeWeb.WebClientApplication.Application_PreRequestHandlerExecute(Object sender, EventArgs e) +79
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Jul 26, 2007 at 4:35 PM
Hi!

How have you loaded your service? From this post’s last message:


If you get a ServiceMissingException when using ServiceDependency, is because no service has been registered in the module CompositionContainer with the type of the property. Please make sure the service you registered is of the same type of the property or, if you registered the service with a different type (using the overload IServiceCollection.AddNew<T>(type registerAs)) make sure the property is of that type.


In case this doesn’t help, could you provide further details of the steps you are following?

Luciano G. Panaro
http://staff.southworks.net/lpanaro
Jul 26, 2007 at 6:16 PM
Thanks for the reply. Here's what's happening:
In the Companies module, I have this in the Load method:
AddModuleServices(moduleContainer.Services)

The only thing in that method is this:
moduleServices.AddNew<CompanyServiceAgent, ICompanyServiceAgent>();

Where I think it is getting hung is here--I think the translator is not getting set up:
InjectionConstructor
public CompanyServiceAgent
(

ServiceDependency IEntityTranslatorService translator
)
{
_translator = translator;
_proxy = new removed.WebClient.Modules.ServiceProxies.CompanyService.CompanyServiceProxy();
}

Any suggestions? I would think that the ServiceDependency would construct the translator, or do I need to somehow directly do that? When I look at the reference implementation, it seems to be using the injection as I am doing.
Thanks
Jul 26, 2007 at 7:48 PM
Hi!

In fact, ServiceDependency attribute does not construct your service if it is not constructed. The Service is created programmatically, here’s the snippet from the RI:

namespace GlobalBank
{
	public class ElectronicBankingApplication : WebClientApplication
	{
		protected override void AddRequiredServices()
		{
            // TBD: Move this line to EFT or move EntityTranslatorService to CWAB and register the service
            // in the Shell module.
            RootContainer.Services.AddNew<EntityTranslatorService, IEntityTranslatorService>();
            base.AddRequiredServices();
		}
		…
	}
}

Maybe the topic from help “How to: Register and Use Services” will be of use for further information about Services in WCSF.

Hope it helps!

Luciano G. Panaro
http://staff.southworks.net/lpanaro
Jul 27, 2007 at 10:44 PM
Thanks a ton -- I missed that file when I walked through the reference implementation. I was just initializing and registering the service within one module, and I thought I was registering it globally.