Accessing and installing app.config based on user specific

713 views Asked by At

I am having 2 app.config files on working for https access and another for http access, if i am having two option button one for http and another for https, if user select 1st option i.e http how i can store inside C:\program files while installing my application and refer my application to use only httpsapp.config file and not httpapp.config file.

Or how i can make my app.config file to work both for https as well as http.

Below is my app.config file while is currently working for http

 <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>

And app.config working in 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>

Anyone can help me out?

1

There are 1 answers

0
Yann39 On

You can use a single config file for http and https, by defining the base address for each one.

I just tried this and it is working fine :

  <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>