如何解决自托管WCF服务的TypeLoadException

时间:2014-12-27 12:41:28

标签: wcf web-config typeloadexception

我有配置文件的web托管项目,我将托管类型从iis托管更改为wcf自托管但我累积了一些问题请帮我解决这些问题:

这是配置文件:

<?xml version="1.0"?>
<configuration>
    <connectionStrings>
       <add name="AdventureWorksEntities" connectionString="metadata=res://*/AdventureWorksModel.csdl|res://*/AdventureWorksModel.ssdl|res://*/AdventureWorksModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.;Initial Catalog=AdventureWorks;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <services>
            <service name="GSM.NTier.Server.Domain.Service.GSMDBDataService">
                <endpoint address="" binding="wsHttpBinding" contract="GSM.NTier.Common.Domain.Service.Contracts.IGSMDBDataService" bindingConfiguration="WS-AT" />
                <endpoint address="basic" binding="basicHttpBinding" contract="GSM.NTier.Common.Domain.Service.Contracts.IGSMDBDataService" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <bindings>
            <wsHttpBinding>
                <binding name="WS-AT" transactionFlow="true" />
            </wsHttpBinding>
        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <serviceAuthorization impersonateCallerForAllOperations="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
</configuration>

这是我使用的自托管代码:

        WebServiceHost host = new WebServiceHost(typeof(GSMDBDataService), new   Uri("http://localhost:8580/GSMDBDataService"));
        WebHttpBinding webHttp = new WebHttpBinding();
        webHttp.MaxReceivedMessageSize = 1000000000000;
        webHttp.ReceiveTimeout = TimeSpan.FromMinutes(30);
        webHttp.SendTimeout = TimeSpan.FromMinutes(30);
        webHttp.TransferMode = TransferMode.Streamed;`
       ` ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IGSMDBDataService), webHttp, "");
        ServiceEndpoint ep1 = host.AddServiceEndpoint(typeof(IGSMDBDataService), webHttp, "basic");
        ServiceEndpoint ep2 = host.AddServiceEndpoint(typeof(IGSMDBDataService), webHttp, "mex");
        ServiceDebugBehavior stp = host.Description.Behaviors.Find<ServiceDebugBehavior>();
`
   `     stp.HttpHelpPageEnabled = false;
        host.Open();
        Console.WriteLine("\t\tService is up and running");
        Console.WriteLine("\t\tService is up and running");
        Console.WriteLine("\t\tPress enter to quit ");
        Console.ReadLine();
        host.Close();

异常截图: enter image description here

这是一个例外细节:

System.TypeLoadException was unhandled
  HResult=-2146233054
  Message=Method 'get_PropertyInfos' in type 'GSM.NTier.Common.Domain.Model.GSMDB.Person' from assembly 'GSM.NTier.Common.Domain.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
  Source=mscorlib
  TypeName=GSM.NTier.Common.Domain.Model.GSMDB.Person
  StackTrace:
       at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
       at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
       at System.Reflection.RuntimeMethodInfo.GetParameters()
       at System.ServiceModel.Description.ServiceReflector.ValidateParameterMetadata(MethodInfo methodInfo)
       at System.ServiceModel.Description.TypeLoader.CreateOperationDescriptions(ContractDescription contractDescription, ContractReflectionInfo reflectionInfo, Type contractToGetMethodsFrom, ContractDescription declaringContract, MessageDirection direction)
       at System.ServiceModel.Description.TypeLoader.CreateContractDescription(ServiceContractAttribute contractAttr, Type contractType, Type serviceType, ContractReflectionInfo& reflectionInfo, Object serviceImplementation)
       at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation)
       at System.ServiceModel.Description.ContractDescription.GetContract(Type contractType, Type serviceType)
       at System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts)
       at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
       at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
       at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
       at System.ServiceModel.Web.WebServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
       at GSM.Server.Hosting.Program.Main(String[] args) in d:\GAMA\Projects\Visual Studio\2014\GDM( GAMA Delivred Manager)\GDM 2.0\GSM\GSM.Server.Hosting\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

1 个答案:

答案 0 :(得分:1)

是否有可能忘记在控制台项目中添加对模型程序集的引用,这会在实例化服务时导致运行时异常?

编辑:

看看this question。似乎很相似。

相关问题