我尝试通过WCF和实体框架构建N层应用程序。我是所有这些人的新手,如果我听起来无知,那就道歉了。
我正在尝试测试,当我尝试通过WCF服务查询数据库时出现此错误。
在配置中找不到指定的命名连接,不打算与EntityClient提供程序一起使用,或者无效。
我只是将我的连接字符串从Entity Framework项目复制粘贴到我的WCF主机web.config,所以我不确定是什么错误。
有什么想法吗?
的web.config
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="AerosPACE_CCADEEntities" connectionString="metadata=res://*/AerospaceModel.csdl|res://*/AerospaceModel.ssdl|res://*/AerospaceModel.msl;provider=System.Data.SqlClient;provider connection string="data source=****;initial catalog=AerosPACE_CCADE;persist security info=True;user id=****;password=****;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="AerospaceCCADE.Server.Domain.Service.AerosPACE_CCADEDataService">
<endpoint address="" binding="wsHttpBinding" contract="AerospaceCCADE.Common.Domain.Service.Contracts.IAerosPACE_CCADEDataService" bindingConfiguration="WS-AT" />
<endpoint address="basic" binding="basicHttpBinding" contract="AerospaceCCADE.Common.Domain.Service.Contracts.IAerosPACE_CCADEDataService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="WS-AT" transactionFlow="true" />
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization impersonateCallerForAllOperations="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
客户端App.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
</connectionStrings>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_DataService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="true" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="67108864"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:5482/AerosPACE_CCADEDataService.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_DataService"
contract="AerospaceCCADE.Common.Domain.Service.Contracts.IAerosPACE_CCADEDataService"
name="AerosPACE_CCADEDataService"/>
</client>
<behaviors>
<endpointBehaviors>
<behavior>
<clientCredentials>
<!--allow server to use client credentials for impersonation-->
<windows allowedImpersonationLevel="Impersonation" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
答案 0 :(得分:1)
您还需要entityFramework部分。
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>