【问题标题】:Metadata Exception on WCF DeployWCF 部署上的元数据异常
【发布时间】:2017-04-03 20:34:16
【问题描述】:

我的项目概述是我有一个 SQL 数据库,其中包含存储在亚马逊 RDS 上的考试信息。我正在创建一个使用实体框架访问该数据库的 WCF Web 服务。然后,这个 WCF 将使用 MSDeploy 通过 Jenkins 管道部署在亚马逊 EC2 上。当我在本地运行我的 WCF 时,它工作得非常好。它也成功部署,我可以远程访问 wcf 的 WSDL。但是,如果我调用任何使用实体框架的方法,我会在部署的 WCF 上遇到元数据异常。

通常这与实体框架连接字符串有关,但就像我说的那样,当我在本地运行 WCF 时,它可以完美地连接到远程 RDS。但无论出于何种原因,它在部署后就无法正常工作。

TLDR:我的 WCF 中的 EF 调用在本地工作,但不是远程工作,我不知道为什么

以下是我的 WCF 的 Web 配置

<?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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2"/>
    <customErrors mode="Off" />
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add service="LMS1701.EA.SOAPAPI.Service1" relativeAddress="./Service1.svc"/>
      </serviceActivations>
    </serviceHostingEnvironment>
    <bindings>
      <basicHttpBinding>
        <binding  name="MyBasicHttpBinding"
                  >
            <security mode ="None">
              <transport clientCredentialType="None"/>
            </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service  name="LMS1701.EA.SOAPAPI.Service1">
        <endpoint  binding="basicHttpBinding" bindingConfiguration ="MyBasicHttpBinding" contract="LMS1701.EA.SOAPAPI.IService1"></endpoint>
       <!-- <host>
          <baseAddresses>
            <add baseAddress="http://localhost:61751/ExamassessmentWCF" />
          </baseAddresses>
        </host>-->
      </service>
      <!-- <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
       <endpoint address=""
                 binding="basicHttpBinding"
                 contract="MyService.IMyService"/>
       <endpoint
           address="mex"
           binding="mexHttpBinding"
           contract="IMetadataExchange"/>

     </service> -->

    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />-->
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
       To browse web app root directory during debugging, set the value below to true.
       Set to false before deployment to avoid disclosing web app folder information.
     -->
    <directoryBrowse enabled="true" />
  </system.webServer>

  <connectionStrings>
    <add name="ExamAssessmentEntities" connectionString="metadata=res://*/DatabaseModel.csdl|res://*/DatabaseModel.ssdl|res://*/DatabaseModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(aws endpoint);initial catalog=ExamAssessment;user id=******;password=******;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

</configuration>

以下是发生错误后的堆栈跟踪。

System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection1 uriRegistry, MetadataArtifactAssemblyResolver 解析器) 在 System.Data.Entity.Core.Metadata.Edm.MetadataCache.SplitPaths(字符串 路径)在 System.Data.Entity.Core.Common.Utils.Memoizer2.Result.GetValue()
at System.Data.Entity.Core.Common.Utils.Memoizer
2.Evaluate(TArg arg) 在 System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetArtifactLoader(DbConnectionOptions 有效连接选项)在 System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions 有效连接选项)在 System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace() 在 System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection 连接,布尔 isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator 翻译器,ColumnMapFactory columnMapFactory) 在 System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel() 在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 在 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型 实体类型)在 System.Data.Entity.Internal.Linq.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext()
在 System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() at System.Linq.Queryable.Where[TSource](IQueryable1 来源, 表达式`1谓词)在 LMS1701.EA.SOAPAPI.Service1.GetAnswersQuestion(Int32 Questid) 在 C:\程序文件 (x86)\Jenkins\workspace\EA-DAL-SVC\ExamAssessmentSOAPAPI\ExamassessmentWCF\Service1.svc.cs:line 201

这是导致上述堆栈跟踪的调用方法

      public List<Answers> GetAnswersQuestion(int Questid)
        {
                AutoMapperConfiguration.Configure();
                List<int> AnswerID = db.QuestionAnswers.Where(c => c.QuestionID == Questid).Select(x => x.AnswerID).ToList(); // this is where the exception occurs
                                  .
                                  .
                                  .
}

这是方法的接口签名

[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetAnswersQuestionQuestID={QuestID}")]
List<Answers> GetAnswersQuestion(int Questid);

【问题讨论】:

    标签: .net entity-framework wcf jenkins amazon-ec2


    【解决方案1】:

    忽略问题已解决。 webconfig中有错别字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 2011-05-01
      • 1970-01-01
      相关资源
      最近更新 更多