Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofac WCF service doesn't initialize in Singleton mode if Autofac Interceptors are also configured. #31

Open
devlic1 opened this issue Jan 14, 2023 · 1 comment

Comments

@devlic1
Copy link

devlic1 commented Jan 14, 2023

Describe the Bug

Autofac WCF service doesn't initialize in Singleton mode if Autofac Interceptors are also configured.

Steps to Reproduce

Sample WCF service project is provided in below github repo. Just set the WCFService as startup project and Service1.svc as Start page and run, you will get the error as

https://github.com/devlic1/AutofacWCFTest

image

Error is coming when we are configuring the service as SingleInstance and Enabling the Interceptors at the same time. If we remove anyone from these, then service works fine. i.e. If we remove the Interceptor OR we remove the SingleInstance (and remove InstanceContextMode from ServiceBehavior), then Service works fine

            builder.RegisterType<WCFService.Service1>()
                   .As<ClassLibrary1.IService1>()
                   .SingleInstance()
                   .EnableInterfaceInterceptors().InterceptedBy(typeof(Interceptor));

Expected Behavior

Service should run fine with both configurations i.e. Interceptors with SingleInstance service

Exception with Stack Trace

<TITLE>The service class of type Castle.Proxies.IService1Proxy both defines a ServiceContract and inherits a ServiceContract from type ClassLibrary1.IService1. Contract inheritance can only be used among interface types. ÿIf a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute. ÿConsider moving the ServiceContractAttribute on type ClassLibrary1.IService1 to a separate interface that type ClassLibrary1.IService1 implements.</TITLE> Error: Cannot obtain Metadata from http://localhost:60837/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:60837/Service1.svc Metadata contains a reference that cannot be resolved: 'http://localhost:60837/Service1.svc'. The requested service, 'http://localhost:60837/Service1.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:60837/Service1.svc There was an error downloading 'http://localhost:60837/Service1.svc'. The request failed with the error message:-- <STYLE> body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:pointer; } @media screen and (max-width: 639px) { pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; } } @media screen and (max-width: 479px) { pre { width: 280px; } } </STYLE>

Server Error in '/' Application.

The service class of type Castle.Proxies.IService1Proxy both defines a ServiceContract and inherits a ServiceContract from type ClassLibrary1.IService1. Contract inheritance can only be used among interface types. ÿIf a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute. ÿConsider moving the ServiceContractAttribute on type ClassLibrary1.IService1 to a separate interface that type ClassLibrary1.IService1 implements.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The service class of type Castle.Proxies.IService1Proxy both defines a ServiceContract and inherits a ServiceContract from type ClassLibrary1.IService1. Contract inheritance can only be used among interface types. ÿIf a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute. ÿConsider moving the ServiceContractAttribute on type ClassLibrary1.IService1 to a separate interface that type ClassLibrary1.IService1 implements.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The service class of type Castle.Proxies.IService1Proxy both defines a ServiceContract and inherits a ServiceContract from type ClassLibrary1.IService1. Contract inheritance can only be used among interface types.  If a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute.  Consider moving the ServiceContractAttribute on type ClassLibrary1.IService1 to a separate interface that type ClassLibrary1.IService1 implements.]   System.ServiceModel.Description.ServiceReflector.GetInterfaces(Type service) +16386111   System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts) +295   System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +160   System.ServiceModel.ServiceHost..ctor(Object singletonInstance, Uri[] baseAddresses) +302   Autofac.Integration.Wcf.AutofacServiceHostFactory.CreateSingletonServiceHost(Object singletonInstance, Uri[] baseAddresses) +56   Autofac.Integration.Wcf.AutofacHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +239   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1928   System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +66   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +757[ServiceActivationException: The service '/Service1.svc' cannot be activated due to an exception during compilation.  The exception message is: The service class of type Castle.Proxies.IService1Proxy both defines a ServiceContract and inherits a ServiceContract from type ClassLibrary1.IService1. Contract inheritance can only be used among interface types.  If a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute.  Consider moving the ServiceContractAttribute on type ClassLibrary1.IService1 to a separate interface that type ClassLibrary1.IService1 implements..]   System.Runtime.AsyncResult.End(IAsyncResult result) +611   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +239   System.Web.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult ar) +231   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +172


Version Information:ÿMicrosoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4494.0 --.
Put the exception with stack trace here.

Dependency Versions

image

Additional Info

@tillig
Copy link
Member

tillig commented Jan 15, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants