Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP & HTTP WCF Services

Can I have a WCF Service Project that has both HTTP (basic http binding) and HTTPS (basic http binding) bindings? For example, I would have:

https://localhost:44303/ServiceA.svc http://localhost:12345/ServiceB.svc

Would there be any benefit to putting them into separate service projects (and separate sites when we deploy the app)?

like image 344
user472292 Avatar asked Mar 08 '26 05:03

user472292


1 Answers

If you already have HTTP binding, you don't need to change code to add HTTPS binding. This is a big advantage of WCF. Instead of adding a separate site, you just add a new endpoint to the configuration file.

Below is an example of configuration with both HTTP and HTTPS.
You can see that there two named bindings: notSecureBinding and secureBinding, which correspond to HTTP and HTTPS.

  <bindings>
    <basicHttpBinding>
      <binding name="notSecureBinding"
               maxBufferSize="2147483647"
               maxReceivedMessageSize="2147483647">
        <security mode="None"/>
      </binding>
      <binding name="secureBinding"
               maxBufferSize="2147483647"
               maxReceivedMessageSize="2147483647">
        <security mode="Transport">
          <transport clientCredentialType="None"/>
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <behaviors>
    <serviceBehaviors>
      <behavior name="StandardServiceBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        <serviceAuthorization principalPermissionMode="None"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="StandardServiceBehavior"
             name="ServiceName">
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="notSecureBinding"
                contract="Namespace.IService"/>
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="secureBinding"
                contract="Namespace.IService"/>
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange"/>
    </service>
  </services>
like image 130
Alex Aza Avatar answered Mar 10 '26 18:03

Alex Aza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!