WCF+EntityFramework+mysql总结
前段时间搞一个项目,用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)]
结束,总结到此:)