How to use IoC.Resolve from WCF

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 лет назад
To populate NopCommerce with products and categories I made a WCF service that can be called from an external system.

To use the CategoryService and ProdcutService I use:

            ICategoryService categoryService = IoC.Resolve<ICategoryService>();
            IProductService productService = IoC.Resolve<IProductService>();

If I use this code from an aspx page in e.g. PageLoad everything works fine and I get the two services.
If I use this code from a method within a WCF service I always get an exception "Unable to cast object".
In this case more specifically:

Unable to cast object of type 'NopSolutions.NopCommerce.BusinessLogic.Data.NopObjectContext' to type 'NopSolutions.NopCommerce.BusinessLogic.Products.IProductService'.

The first call to IoC.Resolve always seems to work, all after that fails (if I switch the 2 lines of code around I get the ProductService and an exception on the CategoryService).

How do I use IoC.Resolve from WCF without getting exceptions?

Thanks,

Jan.
13 лет назад
I have the same issue, did you find a solution?
13 лет назад
Nicolas,

I found a workaround rather than a solution.
I rewrote my service as a plain .asmx webservice, so no more WCF.
More coding and less elegant but it works.
13 лет назад
This is a huge problem for me...

I found this link http://mfelicio.wordpress.com/2010/02/07/resolving-wcf-service-instances-with-an-ioc-container/ but I was not able to solve the issue.

Nobody uses WCF since nop 1.9?
13 лет назад
Hi,
I have the same issue about authentication from wcf.
But I 'm successfull to call IoC.Resolve<ICustomerService>().Login(email, password);

this operation will send me a boolean answer. But When I debug the code. I got the exception "Unable to cast object of type 'NopCommerce.BusinessLogic.Data.NopObjectContext' to type 'NopCommerce.BusinessLogic.Configuration.Settings.ISettingManager'."

here is my post in detail about this problem.


If you found a solution, please aware of me...

Keep battling...
13 лет назад
Still no solution...
Can someone help us?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.