C# 根据特定于用户的配置访问和安装app.config

C# 根据特定于用户的配置访问和安装app.config,c#,wcf,installation,app-config,wcfserviceclient,C#,Wcf,Installation,App Config,Wcfserviceclient,我有两个app.config文件用于https访问,另一个用于http访问,如果我有两个选项按钮,一个用于http,另一个用于https,如果用户在安装我的应用程序时选择第一个选项,即http如何在C:\program文件中存储,并将我的应用程序引用为仅使用httpsapp.config文件而不使用httpapp.config文件 或者如何使我的app.config文件同时适用于https和http 下面是我当前为http工作时的app.config文件 <system.serviceM

我有两个app.config文件用于https访问,另一个用于http访问,如果我有两个选项按钮,一个用于http,另一个用于https,如果用户在安装我的应用程序时选择第一个选项,即http如何在C:\program文件中存储,并将我的应用程序引用为仅使用httpsapp.config文件而不使用httpapp.config文件

或者如何使我的app.config文件同时适用于https和http

下面是我当前为http工作时的app.config文件

 <system.serviceModel>
    <standardEndpoints />
    <bindings>
      <webHttpBinding>
        <binding name="Bind1" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="900000" maxBufferSize="900000" />
      </webHttpBinding>
    </bindings>
    <services>
      <service name="PeripheralServiceImpl" behaviorConfiguration="SvcBhvr">
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="EndPBhvr" bindingConfiguration="Bind1" contract="Server.Contract.IPeripheralService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:18732/Peripheral/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="EndPBhvr">
          <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" faultExceptionEnabled="false" defaultBodyStyle="Wrapped" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="SvcBhvr">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
  </system.serviceModel>
和app.config在https中工作

      <system.serviceModel>
        <standardEndpoints />
          <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

          <bindings>
                  <basicHttpBinding>
                      <binding name ="soapBinding">
                          <security mode="Transport">
                              <transport clientCredentialType="None"/>
                          </security>
                      </binding>
                  </basicHttpBinding>
                  <webHttpBinding>
                      <!--<binding name="httpBinding">-->
                          <binding name="Bind1" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="900000" maxBufferSize="900000" >
                          <security mode="Transport">
                              <transport clientCredentialType="None"/>
                          </security>
                      </binding>
                  </webHttpBinding>  

        </bindings>
        <services>
          <service name="PeripheralServiceImpl" behaviorConfiguration="SvcBhvr">
              <host>
                  <baseAddresses>
                      <add baseAddress="https://localhost:18732/Peripheral/" />
                  </baseAddresses>
              </host>

              <endpoint address="https://localhost:18732/Peripheral/" binding="webHttpBinding" behaviorConfiguration="EndPBhvr" bindingConfiguration="Bind1" 
                        contract="Server.Contract.IPeripheralService">

</endpoint>

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />


          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="EndPBhvr">
                <webHttp /> 
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="SvcBhvr">
              <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

有人可以帮我吗?

您可以通过定义每个配置文件的基址,为http和https使用一个配置文件

我刚试过这个,效果很好:

  <system.serviceModel>
    <services>
      <service name="MyTest.MyService" behaviorConfiguration="ServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:80/WCFtest/service.svc" />
            <add baseAddress="https://localhost:443/WCFtest/service.svc" />
          </baseAddresses>
        </host>
        <endpoint address="/soap" binding="basicHttpBinding" contract="MyTest.IMathService" />
        <endpoint address="/rest" binding="webHttpBinding" contract="MyTest.IMyService" behaviorConfiguration="REST" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="REST">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>