当前位置: 代码迷 >> Web Service >> 急求相助:WCF 中,在SVC中使用实体查询库时报错:“基础提供程序在Open上失败了”。win8 + VS2012 + EF + localDB + IIS
  详细解决方案

急求相助:WCF 中,在SVC中使用实体查询库时报错:“基础提供程序在Open上失败了”。win8 + VS2012 + EF + localDB + IIS

热度:306   发布时间:2016-05-02 02:19:16.0
急求帮助:WCF 中,在SVC中使用实体查询库时报错:“基础提供程序在Open上失败了”。win8 + VS2012 + EF + localDB + IIS
错误:WCF 中,在SVC中使用实体查询库时报错:“基础提供程序在Open上失败了”
说明:操作系统Win8;WCF发布到IIS中;数据库使用VS2012自带的localDB.
一,这是接口定义
    [ServiceContract]
    public interface INeed
    {
        [OperationContract]
        [WebInvoke(
            Method = "POST",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/uploadMdNeed",
            BodyStyle = WebMessageBodyStyle.Bare
            )]
        String uploadMdNeed(MdNeed mdNeed);
    }
二,这是接口实现
public class Need:INeed
    {
        public string uploadMdNeed(MdNeed mdNeed)
        {
            try
            {
                lmEntities lmEtt = new lmEntities();
                NeedTb need = new NeedTb();
                need.SDescribe = "描述描述";
                lmEtt.NeedTb.Add(need);
                lmEtt.SaveChanges();

                return "使用lmEitities类实例,实现新记录的添加。结果是:成功!";
            }
            catch (Exception e)
            {
                return "操作结果是:失败了!!!" + e.Message ;
            }
        }
    }
三,web.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>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetUrl="" httpGetEnabled="true" />
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="httpBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="MyHost.Need_.Need">
        <endpoint address="" binding="webHttpBinding" contract="MyHost.Need_.INeed" behaviorConfiguration="httpBehavior" />
  相关解决方案