Open Closed

How to: Host a WCF service using Abp and DI #223


0
nobruds created

Hello hikalkan,

What is the proper way to use abp framework with a wcf service and consume it on a asp.net mvc application?

I did an example here but its wrong, I'm getting this error:

Component Abp.Domain.Uow.UnitOfWorkDefaultOptions could not be registered. There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name.

I know this happens because of my code, because its registering on every method call. but how should I do it them, where I register my components ?

my code:

GerenciadorBoletadorWCF.svc
public class GerenciadorBoletadorWCF : IGerenciadorBoletadorWCF
    {
        public string GetNumeroBoleto()
        {
            IoContainer IoCDriver = new IoContainer();
            string NumeroBoleto = string.Empty;
            
            dynamic BoletoService = IoCDriver.GetInstance();

            NumeroBoleto = BoletoService.GetBoletoNumero();

            IoCDriver.Release(BoletoService);

            return NumeroBoleto;            
        }
    }

public class IoContainer
    {
        AbpBootstrapper bootstrapper;
        dynamic instance;

        public IoContainer()
        {
            bootstrapper = new AbpBootstrapper();            
            bootstrapper.Initialize();

            instance = bootstrapper.IocManager.Resolve<DependencyDriver>();             
        }

        public void Release(object obj)
        {
            bootstrapper.IocManager.Release(obj);
        }

        public dynamic GetInstance()
        {
            return instance.GetBoletoService();
        }
    }

class DependencyDriver : ITransientDependency
    {
        public readonly IBoletoNumeroService _boletoNumeroService;

        public DependencyDriver(IBoletoNumeroService boletoNumeroService)
        {
            _boletoNumeroService = boletoNumeroService;
        }

        public IBoletoNumeroService GetBoletoService()
        {
            return _boletoNumeroService;
        }
    }

Thanks


5 Answer(s)
  • 0
    hikalkan created
    Support Team

    Hi,

    Yes, it's not true. You should register and initialize ABP only once. Actually, you need to make GerenciadorBoletadorWCF created by dependency injection system. You can search for it (for example: <a class="postlink" href="http://www.codeproject.com/Articles/251265/Dependency-Injection-and-Windows-Communication-Fou">http://www.codeproject.com/Articles/251 ... cation-Fou</a>). Also, where are you hosting WCF? In a Windows Service or Web App? I would share some code if I have, but not. If you can not find solution, write here again.

    Have a nice day.

  • 0
    nobruds created

    Hi

    Nice, I will check this example from code project and come back here with an sample.

    I am hosting on IIS.

    On that example doesn't say nothing about windsors AddFacility<WcfFacility> I will need to change the framework to add that

    Thanks

  • 0
    easyest created

    Could You please give us an update on Your success? I need exactly the same thing - to create wcf service, but I would not like to loose abp functionality.

  • 0
    travisgao created

    if i host wcf by Windows Service ,is that OK?

  • 0
    djrot created

    I want to upload image to the WCF REST service. I also want to pass another parameter to the service. I have created following method for that: Code: