我已经创建了一个 ASP.NET MVC 3 应用程序,并且我在 DAL 中有一个 ADO.NET 实体数据模型,其中也包含用于访问数据的类。
我还创建了一个 WCF restful 服务,用于与我的 android 应用程序进行通信。所以当我尝试在 IIS7 上托管我的服务时,我收到了这个错误:
基础提供程序在 Open 和此处失败:
服务器在处理请求时遇到错误。异常消息是“底层提供程序在打开时失败。”。有关更多详细信息,请参阅服务器日志。异常堆栈跟踪位于
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String mappedOperation, Boolean& closeStoreConnectionOnFailure) 在 System.Data.EntityClient.EntityConnection.Open() 在 System.Data.Objects.ObjectContext.EnsureConnection () 在 System.Data.Objects.ObjectQuery
1.GetResults(Nullable
1 forMergeOption) 在 System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable
1 源)在 System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 源)在 SecurityLayer.Authentification.Auth.VerifAuth(User u) 在 c:\Users\ines\Documents\Visual Studio 2012\Projects\GestionDeComptabilite\ ControleLayer\Authentification\Auth.cs: 第 16 行,位于 ManagementServices.AllServices.Authentification(String pseudo, String password) in c:\Users\ines\Documents\Visual Studio 2012\Projects\GestionDeComptabilite\ManagementServices\AllServices.svc.cs:line 28 在 SyncInvokeAuthentification(Object , Object[] , Object[] ) 在 System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) 在 System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin( System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& 的 MessageRpc& rpc)rpc) 在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) 在 System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
附带说明一下,当我从 Visual Studio 启动它时,我的 WCF 服务没有问题,问题仅出在 IIS 上。当我搜索这个问题时,我尝试了这些作为解决方案提出的东西:
- 从连接字符串中删除集成安全性
- 使用sql认证
- 创建一个帐户并授予其访问数据库的权限,并确保 iis 中的应用程序可以访问数据库
- 添加了除 CGI 之外的“应用程序开发功能”的所有组件
我还尝试了这些链接中提出的所有解决方案,但它们都没有奏效:
还有这个:
如果有人可以提供帮助,我将不胜感激。
有关更多信息,这是我的代码:
using SecurityLayer.Authentification;
using DataRepository.DAL;
using DataRepository.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
namespace ManagementServices
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class AllServices : IAllServices
{
public bool Authentification(string pseudo, string password)
{
User u = new User
{
UserName = pseudo,
Password = password
};
Auth a = new Auth() ;
if (a.VerifAuth(u)) return true;
return false;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace ManagementServices
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IAllServices" in both code and config file together.
[ServiceContract(Namespace="http://Services.Compta.com")]
public interface IAllServices
{
[OperationContract(Name="Authentification" )]
[WebInvoke(UriTemplate = "/Auth/{pseudo}/{password}", Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
bool Authentification(string pseudo, string password);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
<connectionStrings>
<add name="GestionComptabiliteEntities" connectionString="metadata=res://*/Data.GestionComptabiliteModel.csdl|res://*/Data.GestionComptabiliteModel.ssdl|res://*/Data.GestionComptabiliteModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(localDB)\v11.0;attachdbfilename=C:\Users\ines\Documents\Visual Studio 2012\Projects\GestionDeComptabilite\DataRepository\App_Data\GestionComptabilite.mdf;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" /> <identity impersonate="true" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding> <binding name="NewBinding0" /> </basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
<services>
<service name="ManagementServices.AllServices" behaviorConfiguration="restBehavior">
<endpoint address="" behaviorConfiguration="a" binding="webHttpBinding" name="xml" contract="ManagementServices.IAllServices" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="" contract="ManagementServices.IAllServices" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="restBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors> <behavior name="a"> <webHttp /> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel>
</configuration>
请注意,它是 WCF 宁静的应用程序而不是库,我也在 VirtualBox 中的 Windows 7 Ultimate 64 位下运行。