2011-05-12 6 views
0

저는 자체 호스팅 WCF (Windows 서비스)가 있으며 web.config 파일이 있습니다. 기능의WCF에서 web.config에 액세스하는 방법?

내부 하나, 내가 (작동하지 않는)이 코드를 가지고 :

Shell(System.Configuration.ConfigurationManager.AppSettings("ExStream_CMD_File_Path"), AppWinStyle.NormalFocus) 

의 Web.config은 다음과 같습니다

<configuration> 
<configSections> 
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
      <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
      <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
       <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/> 
       <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
       <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
       <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
      </sectionGroup> 
     </sectionGroup> 
    </sectionGroup> 
</configSections> 
    <appSettings> 
<add key="ExStream_CMD_File_Path" value="C:\HelloWorld.cmd"/> 
    </appSettings> 
<connectionStrings/> 
<system.web> 
... 

하나의 이유 또는 다른, 그냥 가지 않을거야. 그래서 콘솔 응용 프로그램 &의 app.config에서 내 응용 프로그램 설정을 참조하려고했습니다. ConfigurationManager.AppSettings를 사용하여 읽으려고했으나 "구성 구성원이 아닙니다"라고 오류가 발생하여 ConfigurationSettings.AppSettings를 시도했지만 "방법이 사용되지 않아서 ConfigurationManager를 사용합니다". 많은!

어떻게하면 WCF의 구성 파일에서 간단한 문자열을 참조 할 수 있습니까?

덕분에, 제이슨

답변

2

내가 Web.config의 창문 서비스에 대한 올바른 구성 파일 이름이 생각하지 않는다는 자체 호스팅 서비스 (이것은 IIS에서 webhosted 서비스에 대한 것). 호스팅 코드에서 AppDomain.CurrentDomain.SetupInformation.ConfigurationFile의 값을 확인하면 설정 파일 이름을 알려줍니다. System.Configuration.ConfigurationManager.AppSettings("ExStream_CMD_File_Path")으로 전화하면 정상적으로 작동합니다.

+0

감사합니다. 티켓이었습니다. IIS 호스팅 프로젝트에서 WFC를 추가하고 이전 WCF와 함께 제공되는 web.config에 키를 저장합니다. 새로운 서비스의 app.config에 넣는 것을 잊어 버렸습니다. 감사!! –

관련 문제