首页 新闻 会员 周边

WCF ADO.NET

0
[已解决问题] 解决于 2013-08-22 15:18
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <!--DeviceService-->
      <service behaviorConfiguration="Metadata"
        name="Service.Service1">
        <endpoint
         address="net.tcp://localhost:8003/DeviceImplementation"
         binding="netTcpBinding" bindingConfiguration=""
         contract="Interface.Interface1">
        </endpoint>
        <endpoint
         address="net.tcp://localhost:8004/DeviceImplementation"
         binding="netTcpBinding" bindingConfiguration=""
         contract="Interface.Interface1">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="mex"  binding="mexTcpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8001/"/>
            <add baseAddress="net.tcp://localhost:8002/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Metadata">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

  <configSections>
     <!--For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468--> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="MyServerContextEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=MyServerContext;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
  
</configuration>

 

项目分为DAL,BLL,Interface,Service四个类库,其中DAL添加ADO.NET实体数据模型,Host为控制台,寄宿服务。那么DAL的app.cnofig文件中的数据库链接字符串要放到什么位置。调用服务的时候一直提示访问失败。

各层直接的引用呢,Host是否需要引用DAL,BLL?

将配置文件写到Host里面时就会出错

GhostRider_zkc的主页 GhostRider_zkc | 初学一级 | 园豆:18
提问于:2013-08-22 14:28
< >
分享
最佳答案
0

放到你的 Host 控制台程序,记住一点,放到你的运行的 exe 程序的 config 中。

需不需要直接引用,你编译下就知道了。

奖励园豆:5
Launcher | 高人七级 |园豆:45045 | 2013-08-22 14:32

不行呢,运行就报错

GhostRider_zkc | 园豆:18 (初学一级) | 2013-08-22 14:39

@GhostRider_zkc: 那你就把引用添加上。

Launcher | 园豆:45045 (高人七级) | 2013-08-22 14:41

@GhostRider_zkc: 大哥,我再说一次,出了什么错误,异常是啥?哪里出了错?

Launcher | 园豆:45045 (高人七级) | 2013-08-22 14:48

@Launcher: 添加了引用也错误,新建控制台,引用DAL,BLL后添加配置文件运行控制台就可以。带上服务的就不行。

GhostRider_zkc | 园豆:18 (初学一级) | 2013-08-22 14:50

@GhostRider_zkc: 在配置文件中把 <system.serviceModel> 放到最后。然后呢,你要先调通你的

WCF服务,也就是保证你的代码和配置是正确的,那么你就建立一个简单的服务,不引用dll,bll什么,就是把WCF服务搞好;接着呢,你再建立一个简单的程序,就只引用DAL,把你的 EF 调通;最后呢,你再合并起来。

Launcher | 园豆:45045 (高人七级) | 2013-08-22 14:55

@Launcher: <system.serviceModel>节点放到最后就正确了,为什么呢?

GhostRider_zkc | 园豆:18 (初学一级) | 2013-08-22 15:03

@GhostRider_zkc: 如果 config 中有 <configSections> 的话,它一定要是第一个节点,这是框架设计上的一个问题,估计是为了性能考虑,采用了流式读取方式,这样,你必须先读取了 <configSections> 节点后,你才能读取 <configSections> 中定义的自定义节点;如果反过来的话,就有问题,因为你还不知道是否有这个自定义节点。可以同我们的代码做个类比:

int a;

a = 10;

你不能写成:

a = 10;

int a;

Launcher | 园豆:45045 (高人七级) | 2013-08-22 15:09

@Launcher: 谢谢,受益匪浅

GhostRider_zkc | 园豆:18 (初学一级) | 2013-08-22 15:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册