WCF部署

时间:2017-04-03 20:34:17

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

我的项目概述是我有一个SQL数据库,其中包含存储在亚马逊RDS上的考试信息。我正在创建一个使用Entity Framework访问该数据库的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(字符串   assemblyName,String resourceName,ICollection 1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection 1 uriRegistry,MetadataArtifactAssemblyResolver resolver)   在   System.Data.Entity.Core.Metadata.Edm.MetadataCache.SplitPaths(字符串   路径)   System.Data.Entity.Core.Common.Utils.Memoizer 2.Result.GetValue()
at System.Data.Entity.Core.Common.Utils.Memoizer
2.评估(TArg arg)   在   System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetArtifactLoader(DbConnectionOptions   effectiveConnectionOptions)   System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions   effectiveConnectionOptions)   System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace()   在   System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection   connection,Boolean isConnectionConstructor,   ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory,   译者翻译,ColumnMapFactory columnMapFactory)at   System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()   在System.Data.Entity.Internal.LazyInternalContext.InitializeContext()   在   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型   entityType)at   System.Data.Entity.Internal.Linq.InternalSet 1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet 1.get_InternalContext()
  在   System.Data.Entity.Infrastructure.DbQuery 1.System.Linq.IQueryable.get_Provider() at System.Linq.Queryable.Where[TSource](IQueryable 1个来源,   表达式`1谓词)at   LMS1701.EA.SOAPAPI.Service1.GetAnswersQuestion(Int32 Questid)in   C:\ Program Files   (86)\詹金斯\工作空间\ EA-DAL-SVC \ ExamAssessmentSOAPAPI \ ExamassessmentWCF \ Service1.svc.cs:线   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);

1 个答案:

答案 0 :(得分:0)

无视问题已经解决。 webconfig中存在拼写错误。

相关问题