WCF+EF+mysql发布到IIS7上

Posted 零七八碎的资料

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WCF+EF+mysql发布到IIS7上相关的知识,希望对你有一定的参考价值。

1.创建一个  【WCF服务应用程序】。

2.增加内部类库的引用,EntityFramework (Version 6.2)。mysql.Data,  MySql.Data.Entity.EF6  (Version 6.9.9)

3.配置Web.config 

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <configuration>
 3   <configSections>
 4     <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
 5     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
 6     <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
 7   </configSections>
 8   <appSettings>
 9     <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
10   </appSettings>
11   <system.web>
12     <compilation debug="true" />
13   </system.web>
14   <entityFramework>
15     <providers>
16       <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
17       <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
18     </providers>
19     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
20       <parameters>
21         <parameter value="mssqllocaldb" />
22       </parameters>
23     </defaultConnectionFactory>
24   </entityFramework>
25   <system.serviceModel>
26     <services>
27       <service behaviorConfiguration="behav1" name="Services.GetServerInfoService">
28         <endpoint address="" binding="wsHttpBinding" bindingConfiguration="" contract="Contracts.IGetServerInfo" />
29         <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
30       </service>
31     </services>
32     <behaviors>
33       <serviceBehaviors>
34         <behavior name="behav1">
35           <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
36           <serviceDebug includeExceptionDetailInFaults="true" />
37         </behavior>
38       </serviceBehaviors>
39     </behaviors>
40     <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
41   </system.serviceModel>
42   <connectionStrings>
43     <add name="testEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=root;password=123456;persistsecurityinfo=True;database=test&quot;" providerName="System.Data.EntityClient" />
44     <add name="testEntities2" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=root;password=123456;persistsecurityinfo=True;database=test&quot;" providerName="System.Data.EntityClient" />
45   </connectionStrings>
46   <system.webServer>
47     <modules runAllManagedModulesForAllRequests="true" />
48     <!--
49         若要在调试过程中浏览 Web 应用程序根目录,请将下面的值设置为 True。
50         在部署之前将该值设置为 False 可避免泄露 Web 应用程序文件夹信息。
51       -->
52     <directoryBrowse enabled="true" />
53   </system.webServer>
54 <system.data>
55     <DbProviderFactories>
56       <remove invariant="MySql.Data.MySqlClient" />
57       <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.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
58     </DbProviderFactories>
59   </system.data>
</
configuration>

4.创建svc文件:

内容:        <%@ ServiceHost Language="C#" Debug="true" Service="Services.GetServerInfoService" %>

5.设置IIS,   右键:添加应用程序

HTTP 404.2 - Not Found" IIS 7.5 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理 

http://blog.csdn.net/testcs_dn/article/details/8726480

C:\\Windows\\Microsoft.NET\\Framework\\V4.0.30319\\aspnet_regiis -i

 

5.设置 应用程序池:高级:启用32位应用程序True

4.0的 设置为允许

 

处理程序映射的设置。

 

访问地址:http://localhost//IISHostService/Service.svc

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-host-a-wcf-service-in-iis

http://www.cnblogs.com/kesalin/archive/2012/08/20/host_wcf_in_iss.html

以上是关于WCF+EF+mysql发布到IIS7上的主要内容,如果未能解决你的问题,请参考以下文章

升级到 .NET 4.5 和 EF5。不再能够部署 WCF 服务。

通过纯代码方式发布WCF服务

WCF 数据服务使用基于 EF 的存储库中的数据

IIS 和服务之间的 WCF TCP 绑定设置

EF4 POCO:快照与 WCF 上的自我跟踪

Flink实时统计入MySQL