前段時間搞一個項目,用WCF+Ef操作Mysql資料庫的,現在,寫一下經驗總結,希望對大家有協助。
1.需下載並安裝MySql Connector Net 6.5.4
2.在ef層和wcf服務層引用dll :Mysql.Data MySql.Data.Entity MySql.Web 三個dll.
3.在ef層產生的config檔案中,需要改動,把產生的* 改成efmodel所在程式的程式集名稱.
<connectionStrings> <add name="t" connectionString="metadata=res://WCFService.Data/PartsSaleMapping.csdl|res://WCFService.Data/PartsSaleMapping.ssdl|
res://WCFService.Data/PartsSaleMapping.msl;provider=MySql.Data.MySqlClient;provider connection string="
server=xxx;User Id=xxx;password=xxx;Persist Security Info=False;database=xxx"" providerName="System.Data.EntityClient"/> </connectionStrings>
4.在Service端config檔案中加入mysql引擎
<system.data> <DbProviderFactories> <clear /> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data>
5.如果用戶端與服務端可有會有大資料轉送時,修改下config檔案
<binding name="BasicHttpBinding_ISaleService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="200000000" maxArrayLength="200000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
6.部署伺服器,需要裝.net framework4.0,伺服器C盤下的machine.config,需要加入mysql引擎。
7.部署的WCF的服務端訪差距如果是帶網域名稱的,服務端Config檔案按以下方式修改
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"><baseAddressPrefixFilters><add prefix="http://www.xxx.cn" /></baseAddressPrefixFilters></serviceHostingEnvironment>
Wcf服務標題中,加入:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
結束,總結到此:)