使用实体框架部署WCF服务的问题

本文关键字:服务 问题 WCF 部署 实体 框架 | 更新日期: 2023-09-27 18:06:25

目前我正在部署WCF服务与实体框架访问sqlite数据库。该服务托管在窗口服务下。部署服务之后,服务就创建好了。我可以从其他机器访问WSDL页面。但是,我无法通过EF从数据库中获取数据。所有工作都是在开发环境下进行的。在部署到其他机器后,当我使用相同的查询时,它抛出一个错误:未能找到或加载注册的。net框架数据提供程序。

我认为这个问题将与sqlite的东西有关。我已经在"远程"机器上安装了。net framework 4.5和System.data.SQLite,但我仍然不能工作。有人知道这个问题的原因吗?谢谢你的帮助。

另外,我是否需要在我的代码中初始化DbProviderFactory以便在app.config文件中使用它?如果有,应该在哪里插入合适的地方?

这是我的窗口服务的app.config文件:

   <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite"/>
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
 type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.84.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServBehave" name="iPhysio_Wcf_Service.Service">
        <host>
          <baseAddresses>
            <add baseAddress="http://86.163.77.253:8733/iPhysio_Wcf_Service/Service/" />
          </baseAddresses>
        </host>
        <endpoint address="soapService" binding="basicHttpBinding" contract="iPhysio_Wcf_Service.IService" />
        <endpoint address="XMLService" behaviorConfiguration="restPoxBehavior" binding="webHttpBinding" contract="iPhysio_Wcf_Service.IService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServBehave">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <!--Behavior for the REST endpoint for Help enability-->
        <behavior name="restPoxBehavior">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <connectionStrings>
    <add name="iPhysioAndroidDBEntities1" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;C:'Users'SiuWai'Desktop'iPhysioAndroidDB&quot;'" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

使用实体框架部署WCF服务的问题

我不确定这是它,但你的连接字符串在配置:

connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;C:'Users'SiuWai'Desktop'iPhysioAndroidDB&quot;'"

似乎引用了C:'Users位置。这是远程服务器上部署SQLite数据库的地方吗?

除此之外,<system.data>部分与DbProviderFactories的东西对我来说看起来不错,我不认为那里有什么错(或者与网上关于如何做到这一点的文献有什么不同)…对不起,我不是。net中使用SQLite的专家——我只是做过几次,作为一个简单的例子来学习。