一、获取主程序配置文件
//一、配置文件读取方式
<appSettings> <!--集成平台Webservice接口地址--> <!--<binding name="WSInterfaceSoap11Binding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="65536" maxReceivedMessageSize="65536" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" messageEncoding="Text"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding>--> <add key="certificate1" value="" /> <add key="certificate2" value="" /> <add key="HOSPITAL_NO" value="11111" /> <add key="FTPIP" value="ftp://192.168.2.57/AIMS" /> <add key="HTTPIP" value="ftp://192.168.2.57/AIMS" /> <add key="USER" value="zyhip" /> <add key="PWD" value="zyhip" /> </appSettings>
//获取方式 FTPIP = ConfigurationManager.AppSettings["FTPIP"].ToString().Trim(); USER = ConfigurationManager.AppSettings["USER"].ToString().Trim(); PWD = ConfigurationManager.AppSettings["PWD"].ToString().Trim(); HTTPIP = ConfigurationManager.AppSettings["HTTPIP"].ToString().Trim();
二、读取各自DLL的配置文件
配置文件信息
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <!--集成平台Webservice接口地址--> <!--<binding name="WSInterfaceSoap11Binding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="65536" maxReceivedMessageSize="65536" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" messageEncoding="Text"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding>--> <add key="certificate1" value="" /> <add key="certificate2" value="" /> <add key="HOSPITAL_NO" value="11111" /> <add key="FTPIP" value="ftp://192.168.2.57/AIMS" /> <add key="HTTPIP" value="ftp://192.168.2.57/AIMS" /> <add key="USER" value="zyhip" /> <add key="PWD" value="zyhip" /> <add key="ClientSettingsProvider.ServiceUri" value="" /> </appSettings> <system.serviceModel> <bindings> <basicHttpBinding> <!--<binding name="CommEntranceWsSoap11Binding" />--> <binding name="CommEntranceWsSoap11Binding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="65536" maxReceivedMessageSize="65536" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" messageEncoding="Text"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> <customBinding> <binding name="CommEntranceWsSoap12Binding"> <textMessageEncoding messageVersion="Soap12" /> <httpTransport /> </binding> </customBinding> </bindings> <client> <endpoint address="http://192.168.2.93:8886/Comm-service/CommEntranceWs" binding="customBinding" bindingConfiguration="CommEntranceWsSoap12Binding" contract="webServiceOp.CommEntranceWsPortType" name="CommEntranceWsHttpSoap12Endpoint" /> <endpoint address="http://192.168.2.93:8886/Comm-service/CommEntranceWs" binding="basicHttpBinding" bindingConfiguration="CommEntranceWsSoap11Binding" contract="webServiceOp.CommEntranceWsPortType" name="CommEntranceWsHttpSoap11Endpoint" /> </client> </system.serviceModel> <system.web> <membership defaultProvider="ClientAuthenticationMembershipProvider"> <providers> <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" /> </providers> </membership> <roleManager defaultProvider="ClientRoleProvider" enabled="true"> <providers> <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" /> </providers> </roleManager> </system.web> </configuration>
读取方式(对应动态链接库为dll名称.config)
System.Configuration.Configuration cfg = System.Configuration.ConfigurationManager.OpenExeConfiguration(AppDomain.CurrentDomain.BaseDirectory + "DLL名称"); FTPIP = cfg.AppSettings.Settings["对应key"].Value.ToString().Trim();