我正在使用EF,WCF和Asp.net的應用程序中工作。該應用程序工作正常,只有一個問題。 EF英孚有一個app.config文件,其中連接字符串存在可以在中間服務是WCF的Asp.net配置文件中添加EF的連接字符串嗎?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/DataAccessStrategy.Components.XYZ.csdl|res://*/DataAccessStrategy.Components.XYZ.ssdl|res://*/DataAccessStrategy.Components.XYZ.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MyDataSource;Initial Catalog=MyDataBase;Persist Security Info=True;User ID=xxx;Password=xxx;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
現在WCF服務是消費者對EF服務,今後在這個配置文件我確實有因爲在相同的連接字符串的條目
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/DataAccessStrategy.Components.XYZ.csdl|res://*/DataAccessStrategy.Components.XYZ.ssdl|res://*/DataAccessStrategy.Components.XYZ.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MyDataSource;Initial Catalog=MyDataBase;Persist Security Info=True;User ID=xxx;Password=xxx;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
<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>
........
............
的asp.net應用程序與WCF相互作用,因爲它的配置文件是如下
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
.......................
.........................
如可以想出的是,在連接字符串存在於2 PLA CES。
現在這是不可行的。所以我已經從實體框架中完全刪除了配置文件(所以現在它存在於wcf應用程序中)並且它工作正常。
但我想要的是,我想使它存在於Asp.net應用程序的web.config文件中,並且想從WCF app.config文件中刪除它。如果我這樣做,我收到錯誤消息
在配置中找不到指定的命名連接,不打算與EntityClient提供程序一起使用,或者無效。
是不是所有可能的我在找什麼或者我問的東西超出範圍?
請幫
糾正你..在這種情況下,我怎麼能讀取連接字符串的WCF中的配置項,將其設置在運行時...? – user1025901
我的意思是在WCF app.cong文件中我有 connectionStrings> ..這個特殊的字符串條目我可以在運行時..如此如何? –
user1025901
正如你所說的「但在這種情況下,你必須將它發送到每個方法調用WCF服務」..如何做到這一點..請你舉個例子 – user1025901