问题
I keep getting a Sequence contains no elements error when trying to install my wcf services.
here is the code in my global.asax:
_container = new WindsorContainer();
_container.Register(Component.For<IWindsorContainer>().Instance(_container))
.AddFacility<WcfFacility>()
.Install(Configuration.FromAppConfig())
.Install(FromAssembly.InDirectory(new AssemblyFilter(HttpRuntime.BinDirectory, "Web*.dll")));
here is my system.servicemodel section in web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<client>
<endpoint address="http://commandservice.website.com/WebsiteCommandService.svc" binding="basicHttpBinding" contract="CommandService.IWebsiteCommandService" name="commandServiceClient"></endpoint>
</client>
</system.serviceModel>
And here is my castle config (within the web.config):
<castle>
<components>
<component
id="commandService"
type="CommandService.WebsiteCommandService, CommandService"
wcfEndpointConfiguration="commandServiceClient" />
</components>
</castle>
Am I missing something obvious?
UPDATE:
here is the stack trace:
[InvalidOperationException: Sequence contains no elements]
System.Linq.Enumerable.Single(IEnumerable`1 source) +371
Castle.Facilities.WcfIntegration.WcfClientExtension.ObtainServiceContract(ComponentModel model, IWcfClientModel clientModel) in c:\TeamCity\buildAgent\work\a19756d977ce9d2c\src\Castle.Facilities.WcfIntegration\Client\WcfClientExtension.cs:239
Castle.Facilities.WcfIntegration.WcfClientExtension.ResolveClientModel(ComponentModel model) in c:\TeamCity\buildAgent\work\a19756d977ce9d2c\src\Castle.Facilities.WcfIntegration\Client\WcfClientExtension.cs:234
Castle.Facilities.WcfIntegration.WcfClientExtension.Kernel_ComponentModelCreated(ComponentModel model) in c:\TeamCity\buildAgent\work\a19756d977ce9d2c\src\Castle.Facilities.WcfIntegration\Client\WcfClientExtension.cs:189
Castle.MicroKernel.ComponentModelDelegate.Invoke(ComponentModel model) +0
Castle.MicroKernel.DefaultKernel.AddCustomComponent(ComponentModel model, Boolean isMetaHandler) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\DefaultKernel.cs:281
Castle.MicroKernel.DefaultKernel.Register(IRegistration[] registrations) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\DefaultKernel.cs:536
Castle.Windsor.WindsorContainer.Register(IRegistration[] registrations) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\Windsor\WindsorContainer.cs:482
Castle.Windsor.Installer.DefaultComponentInstaller.SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\Windsor\Installer\DefaultComponentInstaller.cs:211
Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers, DefaultComponentInstaller scope) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\Windsor\WindsorContainer.cs:317
Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\Windsor\WindsorContainer.cs:453
Website.MvcApplication.ConfigureContainer() in C:\Users\Wayne Douglas\Dev\ProjectWebsite\Website\Global.asax.cs:65
Website.MvcApplication.Application_Start() in C:\Users\Wayne Douglas\Dev\ProjectWebsite\Website\Global.asax.cs:53
[HttpException (0x80004005): Sequence contains no elements]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +4052053
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +352
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375
[HttpException (0x80004005): Sequence contains no elements]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11686928
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4863749
UPDATE
the problem seems to be somewhere else now - it's like it's trying to resolve the component as if it were a normal object not a wcf service. baring in mind the service works - when trying to resolve it using the wcf i get an error on the ctor:
public WebSiteCommandService(ICommandService service)
{
_service = service;
}
It says that there is no component for ICommandService
why is the client container trying to resolve that?
it's like the wcffacility stuff is being skipped completely?
Here is the stack:
[InstanceNotFoundInEnvironmentConfigurationException: Could not find requested type Ncqrs.Commanding.ServiceModel.ICommandService in the NcqrsEnvironment configuration. Make sure that the NcqrsEnvironment is configured correctly or that defaults are correctly set.]
Ncqrs.NcqrsEnvironment.Get() in C:\Users\Wayne Douglas\Dev\ProjectWebsite\ThirdParty\NCQRS\src\Ncqrs\NcqrsEnvironment.cs:96
CommandService.WebsiteCommandService..cctor() in C:\Users\Wayne Douglas\Dev\ProjectWebsite\CommandService\WebsiteCommandService.svc.cs:17
[TypeInitializationException: The type initializer for 'CommandService.WebsiteCommandService' threw an exception.]
System.Runtime.Serialization.FormatterServices.nativeGetUninitializedObject(RuntimeType type) +0
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate constructor, Object[] arguments, Type implType) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\ComponentActivator\DefaultComponentActivator.cs:151
[ComponentActivatorException: ComponentActivator: could not instantiate CommandService.WebsiteCommandService]
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate constructor, Object[] arguments, Type implType) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\ComponentActivator\DefaultComponentActivator.cs:163
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\ComponentActivator\DefaultComponentActivator.cs:116
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\ComponentActivator\DefaultComponentActivator.cs:66
Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\ComponentActivator\AbstractComponentActivator.cs:80
Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Lifestyle\AbstractLifestyleManager.cs:81
Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Lifestyle\SingletonLifestyleManager.cs:63
Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Handlers\DefaultHandler.cs:124
Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Handlers\DefaultHandler.cs:98
Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveCore(CreationContext context, ComponentModel model, DependencyModel dependency) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Resolvers\DefaultDependencyResolver.cs:308
Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Resolvers\DefaultDependencyResolver.cs:158
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\ComponentActivator\DefaultComponentActivator.cs:292
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\ComponentActivator\DefaultComponentActivator.cs:85
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\ComponentActivator\DefaultComponentActivator.cs:66
Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\ComponentActivator\AbstractComponentActivator.cs:80
Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Lifestyle\AbstractLifestyleManager.cs:81
Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Lifestyle\AbstractLifestyleManager.cs:70
Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Handlers\DefaultHandler.cs:124
Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\Handlers\DefaultHandler.cs:98
Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\DefaultKernel.cs:777
Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) in d:\BuildAgent\work\60b7fa65294e7792\src\Castle.Windsor\MicroKernel\DefaultKernel_Resolve.cs:225
Website.WindsorControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) in C:\Users\Wayne Douglas\Dev\ProjectWebsite\Website\WindsorControllerFactory.cs:24
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +93
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +346
System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +71
System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +19
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +161
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +405
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
回答1:
I think your system.servicemodel element in your web.config is not quite right. If you are hosting the service from your web application you would not have a client element in there - instead of the client element I think you should have a services element that looks like this:
<services>
<service name="CommandService.WebsiteCommandService">
<endpoint address="http://commandservice.website.com/WebsiteCommandService.svc"
binding="basicHttpBinding"
name="commandService"
contract="CommandService.IWebsiteCommandService" />
</service>
</services>
回答2:
I finally got this working!!
the type in the component config needed to be the interface - the service. I left out the service attribute and it fired into action!
And the system.servicemodel worked with client config.
Don't know if this is a bug?
来源:https://stackoverflow.com/questions/8215275/wcffacility-sequence-contains-no-elements