WCF 部署上的元数据异常



我的项目的概述是,我有一个 SQL 数据库,其中包含存储在 Amazon RDS 上的考试信息。 我正在创建一个使用实体框架访问该数据库的 WCF Web 服务。然后,此 WCF 将使用 MSDeploy 通过 Jenkins 管道部署在 Amazon 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 程序集名称、字符串资源名称、ICollection1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection1 uriRegistry、元数据工件Assembly解析器解析器) 在 System.Data.Entity.Core.Metadata.Edm.MetadataCache.SplitPaths(String 路径)在 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 connection, boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, 翻译器翻译器,ColumnMapFactory columnMapFactory) at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel() at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 在 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type 实体类型)在 System.Data.Entity.Internal.Linq.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() at System.Linq.Queryable.Where[TSource](IQueryable1 个源, 表达式'1谓词)在 LMS1701。道肥皂。Service1.GetAnswersQuestion(Int32 Questid) in 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);

忽略问题已解决。 网络配置中有拼写错误。

最新更新