WCF 服务在 IIS 中实施后显示错误
在我的项目中,我使用 Enterprise Library 连接到数据库。当我直接从 Visual Studio 运行应用程序时,它工作正常。
但是,当托管在同一台计算机上的 IIS 中时,这显示连接到数据库时出错。我添加了日志跟踪并收到以下错误
依赖关系解析失败,类型 = “Microsoft.Practices.EnterpriseLibrary.Data.Database”,名称= “(没有任何)”。 while:解决时发生异常。例外是: InvalidOperationException - 无法构造数据库类型。 您必须配置容器以提供该值。 - - - - - - - - - - - - - - - - - - - - - - - - 当时的 例外,容器是:
正在解析 Microsoft.Practices.EnterpriseLibrary.Data.Database,(无) |异常:Microsoft.Practices.ServiceLocation.ActivationException: 尝试获取类型实例时发生激活错误 数据库,键“”---> Microsoft.Practices.Unity.ResolutionFailedException:解决 依赖失败,类型= “Microsoft.Practices.EnterpriseLibrary.Data.Database”,名称= “(没有任何)”。 while:解决时发生异常。例外是: InvalidOperationException - 无法构造数据库类型。 您必须配置容器以提供该值。 - - - - - - - - - - - - - - - - - - - - - - - - 当时的 例外,容器是:
正在解析 Microsoft.Practices.EnterpriseLibrary.Data.Database,(无) ---> System.InvalidOperationException:数据库类型不能是 建造的。您必须配置容器以提供此值。
在 Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext 上下文,SelectedConstructor selectedConstructor) at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext 上下文)在 Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext 上下文)在 Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext 上下文,NamedTypeBuildKey buildKey)位于 Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext 上下文)在 Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext 上下文)位于 Microsoft.Practices.Unity.UnityContainer.DoBuildUp(类型 t,现有对象,字符串名称,IEnumerable1resolverOverrides)
1resolverOverrides)位于 Microsoft.Practices.Unity.UnityContainer.DoBuildUp(类型 t,字符串 名称,IEnumerable`1resolverOverrides)位于 Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(类型 serviceType, String key) --- 内部异常堆栈跟踪结束 --- 在 Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(类型 服务类型,字符串键)位于 Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](字符串 键)在 Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.InnerCreateDatabase(字符串 名称)
--- 内部异常堆栈跟踪结束 --- at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(类型 t,对象 现有的,字符串名称,IEnumerable
我的服务的 web.config
包含如下
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data"/>
</configSections>
<dataConfiguration defaultDatabase="OracleConnection">
<providerMappings>
<add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data" name="Oracle.DataAccess.Client"/>
</providerMappings>
</dataConfiguration>
<connectionStrings>
<add name="OracleConnection" providerName="Oracle.DataAccess.Client" connectionString="User Id=***;Password=****;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=*****)(PORT=1500)) (CONNECT_DATA=(SERVER = DEDICATED) (SERVICE_NAME =*****)));"/>
<add name="SybaseConnection" connectionString="providerName=Sybase.ASEOLEDBProvider;Server=****;Port=5050;Catalog=**;User Id=***;Password=****"/>
</connectionStrings>
我尝试了很多但无法找到问题的原因。 :(
我检查了该文件夹的权限,每个人都具有完全控制权。IIS 中的 WCF 服务匿名访问已启用。
有人可以帮忙吗?
In my project I am using Enterprise Library to connect to database. It is working fine when I run the application from Visual Studio directly.
But this is showing error connecting to database when hosted in IIS on same machine. I have added log trace and got the following error
Resolution of the dependency failed, type =
"Microsoft.Practices.EnterpriseLibrary.Data.Database", name =
"(none)". Exception occurred while: while resolving. Exception is:
InvalidOperationException - The type Database cannot be constructed.
You must configure the container to supply this value.
----------------------------------------------- At the time of the
exception, the container was:Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,(none)
| Exception:Microsoft.Practices.ServiceLocation.ActivationException:
Activation error occured while trying to get instance of type
Database, key "" --->
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the
dependency failed, type =
"Microsoft.Practices.EnterpriseLibrary.Data.Database", name =
"(none)". Exception occurred while: while resolving. Exception is:
InvalidOperationException - The type Database cannot be constructed.
You must configure the container to supply this value.
----------------------------------------------- At the time of the
exception, the container was:Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,(none)
---> System.InvalidOperationException: The type Database cannot be
constructed. You must configure the container to supply this value.
at
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext
context, SelectedConstructor selectedConstructor) at
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext
context, NamedTypeBuildKey buildKey) at
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
context) at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type
t, Object existing, String name, IEnumerable1 resolverOverrides)
1 resolverOverrides) at
--- End of inner exception stack trace --- at
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object
existing, String name, IEnumerable
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String
name, IEnumerable`1 resolverOverrides) at
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type
serviceType, String key) --- End of inner exception stack trace ---
at
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type
serviceType, String key) at
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String
key) at
Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.InnerCreateDatabase(String
name)
My web.config
of service is contains as below
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data"/>
</configSections>
<dataConfiguration defaultDatabase="OracleConnection">
<providerMappings>
<add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data" name="Oracle.DataAccess.Client"/>
</providerMappings>
</dataConfiguration>
<connectionStrings>
<add name="OracleConnection" providerName="Oracle.DataAccess.Client" connectionString="User Id=***;Password=****;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=*****)(PORT=1500)) (CONNECT_DATA=(SERVER = DEDICATED) (SERVICE_NAME =*****)));"/>
<add name="SybaseConnection" connectionString="providerName=Sybase.ASEOLEDBProvider;Server=****;Port=5050;Catalog=**;User Id=***;Password=****"/>
</connectionStrings>
I tried a lot but unable to find the cause of issue. :(
I checked the permission on the folder and Everyone has full control. WCF Service in IIS Anonymous access is enabled.
Could anyone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在使用的程序集找不到它所依赖的程序集之一,请确保所有依赖项都位于 GAC 中或 Web 应用程序的 bin 文件夹中。
The assembly you are using cannot find one of the assemblies it depends on, make sure all dependencies are either in the GAC or in the bin folder of your web app.
当我在 IIS 中启用 32 位应用程序时,错误已更改为
连接字符串正确,适用于 Visual Studio。
我们需要在 Oralce 部分进行任何设置才能从 IIS 访问连接吗?
当更新 oracle 的 sqlnet.ora 文件时,这工作得很好。
When i enabled 32 bit applications in IIS the error has been changed to
The connection string is correct which is working with visual studio.
Is there any setting we need to do in Oralce part to acces connection from IIS?
This worked fine when updated sqlnet.ora file of oracle.