本文介绍了将代码转换为配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 有谁知道我怎么做将以下代码转换为app.config中的条目? private 静态 ServiceHost CreateServiceHost()Does anybody know how I can convert the codes below into entries in app.config?private static ServiceHost CreateServiceHost() { ServiceHost serviceHost = new ServiceHost ( typeof (CalculatorService));ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)); serviceHost.Credentials.ServiceCertificate.SetCertificate(LocalhostCertificateSubjectName,serviceHost.Credentials.ServiceCertificate.SetCertificate(LocalhostCertificateSubjectName, StoreLocation .LocalMachine,StoreLocation.LocalMachine, StoreName .My);StoreName.My); ServiceEndpoint serviceEndpoint = serviceHost.AddServiceEndpoint( typeof (ICalculator),ServiceEndpoint serviceEndpoint = serviceHost.AddServiceEndpoint(typeof(ICalculator), GetServiceBinding(), ////////GetServiceBinding(), //////// ServiceAddress);ServiceAddress); ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior ();ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior(); me tadataBehavior.HttpGetEnabled = true ;metadataBehavior.HttpGetEnabled = true; metadataBehavior.HttpGetUrl = new Uri (ServiceAddress); ///////metadataBehavior.HttpGetUrl = new Uri(ServiceAddress); /////// serviceHost.Description.Behaviors.Add(metadataBehavior);serviceHost.Description.Behaviors.Add(metadataBehavior); serviceHost.AddServiceEndpoint( typeof ( IMetadataExchange ), MetadataExchangeBindings .CreateMexHttpBinding(),ServiceAddress + " / mex" );serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), ServiceAddress + "/mex"); //// //必须在服务主机上设置所有WCF设置后调用此项// This must be called after all WCF settings are set on the service host so the // Geneva Framework令牌处理程序可以选择相关设置。// Geneva Framework token handlers can pick up the relevant settings. //// FederatedServiceCredentials .ConfigureServiceHost(serviceHost);FederatedServiceCredentials.ConfigureServiceHost(serviceHost); AddKnownIssuers(( FederatedServiceCredentials )serviceHost.Credentials);AddKnownIssuers((FederatedServiceCredentials)serviceHost.Credentials); return serviceHost;return serviceHost;} private static 空隙 AddKnownIssuers( FederatedServiceCredentials federatedServiceCredentials)private static void AddKnownIssuers(FederatedServiceCredentials federatedServiceCredentials) { Saml11SecurityTokenHandler tokenHandler =( Saml11SecurityTokenHandler )federatedServiceCredentials.SecurityTokenHandlers [ typeof ( SamlSecurityToken )];Saml11SecurityTokenHandler tokenHandler = (Saml11SecurityTokenHandler)federatedServiceCredentials.SecurityTokenHandlers[typeof(SamlSecurityToken)]; tokenHandler.SamlSecurityTokenRequirement.IssuerNameRegistry = new X509IssuerNameRegistry(STSCertificateSubjectName);tokenHandler.SamlSecurityTokenRequirement.IssuerNameRegistry = new X509IssuerNameRegistry(STSCertificateSubjectName);}推荐答案或多或少......我认为可以这样做:More or less... I think it could be done like this: 这篇关于将代码转换为配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-01 06:27