Base solution for your next web application
BLACK FRIDAY
From Nov 21
To Dec 1
XXDAYS : XXHRS : XXMIN : XXSEC
SAVE UP TO$3K
Also valid for the
existing customers!
Open Closed

Register WebService for DI #4057


0
pointlevel created

Hello!

I have added a webService to my application. But when i try to use this service as Dependency Injection i get an error:

'MyApp.BilvisionService.BilvisionAppService' is waiting for the following dependencies:
- Service 'BVServiceReference.WSCETestSoap' which was not registered.

How can i register this webService?

Kind regards!


8 Answer(s)
  • 0
    aaron created
    Support Team

    Make WSCETestSoap implement ITransientDependency, or register in your module's PreInitialize() method:

    IocManager.Register<WSCETestSoap>(DependencyLifeStyle.Transient);
    
  • 0
    pointlevel created

    Thanks. But now the errors continue down the chain.

    'BVServiceReference.WSCETestSoapClient' is waiting for the following dependencies:
    - Parameter 'endpointConfiguration' which was not provided. Did you forget to set the dependency?
    - Parameter 'remoteAddress' which was not provided. Did you forget to set the dependency?
    - Service 'System.ServiceModel.EndpointAddress' which was not registered.
    - Service 'System.ServiceModel.Channels.Binding' which was not registered
    

    This is the WSCETestSoapClient-class:

    public partial class WSCETestSoapClient : System.ServiceModel.ClientBase<BVServiceReference.WSCETestSoap>, BVServiceReference.WSCETestSoap, ITransientDependency
        {
            
        /// <summary>
        /// Implement this partial method to configure the service endpoint.
        /// </summary>
        /// <param name="serviceEndpoint">The endpoint to configure</param>
        /// <param name="clientCredentials">The client credentials</param>
        static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
            
            public WSCETestSoapClient(EndpointConfiguration endpointConfiguration) : 
                    base(WSCETestSoapClient.GetBindingForEndpoint(endpointConfiguration), WSCETestSoapClient.GetEndpointAddress(endpointConfiguration))
            {
                this.Endpoint.Name = endpointConfiguration.ToString();
                ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
            }
            
            public WSCETestSoapClient(EndpointConfiguration endpointConfiguration, string remoteAddress) : 
                    base(WSCETestSoapClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
            {
                this.Endpoint.Name = endpointConfiguration.ToString();
                ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
            }
            
            public WSCETestSoapClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : 
                    base(WSCETestSoapClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
            {
                this.Endpoint.Name = endpointConfiguration.ToString();
                ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
            }
            
            public WSCETestSoapClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                    base(binding, remoteAddress)
            {
            }
            
            public System.Threading.Tasks.Task<BVServiceReference.STRUCGrundfraga> GrundfragaAsync(string Regnr, string UserID, string Password)
            {
                return base.Channel.GrundfragaAsync(Regnr, UserID, Password);
            }
            
            public System.Threading.Tasks.Task<BVServiceReference.STRUCTeknikfraga> TeknikfragaAsync(string Regnr, string UserID, string Password)
            {
                return base.Channel.TeknikfragaAsync(Regnr, UserID, Password);
            }
            
            public System.Threading.Tasks.Task<BVServiceReference.STRUCTeknikfragaNY> TeknikfragaV2Async(string Regnr, string UserID, string Password)
            {
                return base.Channel.TeknikfragaV2Async(Regnr, UserID, Password);
            }
            
            public System.Threading.Tasks.Task<BVServiceReference.STRUCDispensFraga> DispensfragaAsync(string Regnr, string UserID, string Password, string Sidref)
            {
                return base.Channel.DispensfragaAsync(Regnr, UserID, Password, Sidref);
            }
            
            public System.Threading.Tasks.Task<BVServiceReference.StrucForegaendeAgareFraga> ForegaendeAgarefragaAsync(string Regnr, string UserID, string Password, string Sidref)
            {
                return base.Channel.ForegaendeAgarefragaAsync(Regnr, UserID, Password, Sidref);
            }
            
            public System.Threading.Tasks.Task<BVServiceReference.StrucForegaendeAgareFragaV2> ForegaendeAgarefragaV2Async(string Regnr, string UserID, string Password, string Sidref)
            {
                return base.Channel.ForegaendeAgarefragaV2Async(Regnr, UserID, Password, Sidref);
            }
            
            public System.Threading.Tasks.Task<BVServiceReference.StrucBesiktningsFraga> BesiktningsfragaAsync(string Regnr, string UserID, string Password, string Sidref)
            {
                return base.Channel.BesiktningsfragaAsync(Regnr, UserID, Password, Sidref);
            }
            
            public virtual System.Threading.Tasks.Task OpenAsync()
            {
                return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
            }
            
            public virtual System.Threading.Tasks.Task CloseAsync()
            {
                return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
            }
            
            private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
            {
                if ((endpointConfiguration == EndpointConfiguration.WSCETestSoap))
                {
                    System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
                    result.MaxBufferSize = int.MaxValue;
                    result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
                    result.MaxReceivedMessageSize = int.MaxValue;
                    result.AllowCookies = true;
                    result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
                    return result;
                }
                if ((endpointConfiguration == EndpointConfiguration.WSCETestSoap12))
                {
                    System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
                    System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
                    textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
                    result.Elements.Add(textBindingElement);
                    System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
                    httpsBindingElement.AllowCookies = true;
                    httpsBindingElement.MaxBufferSize = int.MaxValue;
                    httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
                    result.Elements.Add(httpsBindingElement);
                    return result;
                }
                throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
            }
            
            private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
            {
                if ((endpointConfiguration == EndpointConfiguration.WSCETestSoap))
                {
                    return new System.ServiceModel.EndpointAddress("https://www1.bilvision.se/wsce/wsceTest.asmx");
                }
                if ((endpointConfiguration == EndpointConfiguration.WSCETestSoap12))
                {
                    return new System.ServiceModel.EndpointAddress("https://www1.bilvision.se/wsce/wsceTest.asmx");
                }
                throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
            }
            
            public enum EndpointConfiguration
            {
                
                WSCETestSoap,
                
                WSCETestSoap12,
            }
        }
    
  • 0
    aaron created
    Support Team

    Thanks. But now the errors continue down the chain.

    So do the same.

  • 0
    pointlevel created

    Yes, i did. Like this:

    IocManager.Register<System.ServiceModel.EndpointAddress>(DependencyLifeStyle.Transient);
    IocManager.Register<System.ServiceModel.Channels.Binding>(DependencyLifeStyle.Transient);
    

    After that i get this error:

    HandlerException: Can't create component 'BVServiceReference.WSCETestSoapClient' as it has dependencies to be satisfied.
    
  • 0
    aaron created
    Support Team

    Which dependencies?

  • 0
    pointlevel created

    The error doesnt mention any specific dependencies.. This is the complete exception:

    Castle.MicroKernel.Handlers.HandlerException: Can't create component 'BVServiceReference.WSCETestSoapClient' as it has dependencies to be satisfied.
    
       vid Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
       vid Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
       vid Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
       vid Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency)
       vid Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernel(CreationContext context, ComponentModel model, DependencyModel dependency)
       vid Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveCore(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
       vid Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
       vid Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context)
       vid Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context)
       vid Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context)
       vid Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden)
       vid Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally)
       vid Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
       vid Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
       vid Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
       vid Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
       vid Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency)
       vid Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernel(CreationContext context, ComponentModel model, DependencyModel dependency)
       vid Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveCore(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
       vid Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
       vid Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context)
       vid Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context)
       vid Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context)
       vid Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden)
       vid Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally)
       vid Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
       vid Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
       vid Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
       vid Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
       vid Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy)
       vid Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
       vid Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments)
       vid Castle.Windsor.WindsorContainer.Resolve(Type service)
       vid Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.ResolveInstanceOrNull(Type serviceType, Boolean isOptional)
       vid Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetServiceInternal(Type serviceType, Boolean isOptional)
       vid Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetRequiredService(Type serviceType)
       vid Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
       vid Microsoft.AspNetCore.Mvc.Controllers.ServiceBasedControllerActivator.Create(ControllerContext actionContext)
       vid Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController0(ControllerContext controllerContext)
       vid Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       vid Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       vid Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ExceptionContext context)
       vid Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       vid Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
       vid Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       vid Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       vid Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       vid Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       vid Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       vid Microsoft.AspNetCore.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<<AdaptWebSockets>b__0>d.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       vid Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.<Invoke>d__4.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       vid MyApp.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c.<<UseJwtTokenMiddleware>b__0_0>d.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       vid Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
       vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       vid Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
    
  • 0
    aaron created
    Support Team

    Is that from the page or error log? Can you show a screenshot of the page?

  • 0
    pointlevel created

    <a class="postlink" href="https://snag.gy/x73GIM.jpg">https://snag.gy/x73GIM.jpg</a>