use unity in wcf

Nov 21, 2012 at 7:49 AM

when I test service with wcftestclient,if I call the function throws exception:

Resolution of the dependency failed, type = "Services.SysManager.Impl.SysDepartmentUserService", name = "(none)".Exception occurred while: while resolving.Exception is: InvalidOperationException - The type DbConnection does not have an accessible constructor.-----------------------------------------------At the time of the exception, the container was:
  Resolving Services.SysManager.Impl.SysDepartmentUserService,(none)  Resolving parameter "sysUserDal" of constructor Services.SysManager.Impl.SysDepartmentUserService(PianoManager.DAL.Repository.Repositories.Repository`1[[PianoManager.Model.SysManager.SysUser, PianoManager.Model, Version=, Culture=neutral, PublicKeyToken=null]] sysUserDal, PianoManager.DAL.Repository.Repositories.Repository`1[[PianoManager.Model.SysManager.SysUserFavorite, PianoManager.Model, Version=, Culture=neutral, PublicKeyToken=null]] sysUserFavoriteDal, PianoManager.DAL.UnitOfWork.UnitOfWork unitOfWork)    Resolving PianoManager.DAL.Repository.Repositories.Repository`1[PianoManager.Model.SysManager.SysUser],(none)    Resolving parameter "context" of constructor PianoManager.DAL.Repository.Repositories.Repository`1[[PianoManager.Model.SysManager.SysUser, PianoManager.Model, Version=, Culture=neutral, PublicKeyToken=null]](System.Data.Entity.DbContext context)      Resolving System.Data.Entity.DbContext,(none)      Resolving parameter "existingConnection" of constructor System.Data.Entity.DbContext(System.Data.Common.DbConnection existingConnection, System.Data.Entity.Infrastructure.DbCompiledModel model, System.Boolean contextOwnsConnection)        Resolving System.Data.Common.DbConnection,(none)

Server stack trace:    在 System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)   在 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)   在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)   在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)   在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:    在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)   在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)   在 ISysDepartmentUserService.GetAllUser()   在 SysDepartmentUserServiceClient.GetAllUser()

I have send mail to randylevy


Nov 22, 2012 at 4:37 AM

This sounds like the same issue you were having in the summer: .  

Randy Levy
Enterprise Library support engineer 

Nov 22, 2012 at 5:13 AM


But the config file I copy from the win form project that run is good.

And in my wcf service library test project use the same config,the test program is ok

only in my IISHost when I call the service function not good!

Nov 22, 2012 at 5:49 AM

I have sent the code to you!did u recieved?

Nov 27, 2012 at 2:14 AM

I have resolved it

because in my winform app.config file every class resolve by not have name.

Nov 27, 2012 at 3:41 AM

Good to hear and thanks for letting us know how you worked it out!

Randy Levy
Enterprise Library support engineer 

Nov 27, 2012 at 4:08 AM

my winfom app.config is like :

<register type="ISysDepartmentUserService" mapTo="SysDepartmentUserService" name="sysDepartmentUserService">



when I use unity.wcf can not tell unity container to resolve by name ,so only delete name like :

<register type="ISysDepartmentUserService" mapTo="SysDepartmentUserService">


It works ok!