2

Hello,

I know how to create a self hosted wcf for http or https, but not at the same time.

I would like a wcf for this 2 urls :

  1. https:// 127.0.0.1:13070/ProxySips/
  2. http:// 127.0.0.1:13070/ProxySips/

At the moment I have the configuration for https (with a certificate: makecert + netsh) and it works fine:

app.config

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basicHttp" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="ProxySips_Wcf.Sips" behaviorConfiguration="ProxySips_Wcf.ProxySipsBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="https://127.0.0.1:13070/ProxySips/"   />
      </baseAddresses>
    </host>
    <endpoint address="" binding="basicHttpBinding"
              bindingConfiguration="basicHttp"
              contract="ProxySips_Wcf.ISips"/>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ProxySips_Wcf.ProxySipsBehavior">
      <serviceMetadata  httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="True" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Host

var serviceType = typeof(ProxySips_Wcf.Sips);
var host = new ServiceHost(serviceType);
host.Open();

Can help me set up the http version for the same address?

Many thanks

Bob
  • 1,011
  • 3
  • 12
  • 28
  • Was this ever resolved? Im trying to figure out if WCF can listen for http and https on the same URI/port at the same time, or not. So far, I havent managed to. – Ted Aug 16 '19 at 20:12

1 Answers1

1

You can do this through the use of Multiple Endpoints. With multiple endpoints you can support the same service over multiple protocols (HTTP and HTTPS in your case).

So you will need to add the following ServiceBehavior:

<behavior name="MyUnsecureServiceBehavior">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="false" />
     <dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>

Then the following Binding:

<basicHttpBinding>
  <binding name= MyUnsecureBindingConfig"
                 maxBufferPoolSize="2147483647" 
                 maxReceivedMessageSize="2147483647" 
                 messageEncoding="Text">
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
                   maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                   maxNameTableCharCount="2147483647" />
     <security mode="None">
         <transport clientCredentialType="None" />
         <message establishSecurityContext="false" />
     </security>
</basicHttpBinding>

And lastly the following Address configuration:

<service behaviorConfiguration="MyUnsecureServiceBehavior"
                         name="MyUnsecureService">
   <endpoint address="http://127.0.0.1:13070/ProxySips/"
             binding="basicHttpBinding"
             contract="ProxySips_Wcf.ISips"
             bindingConfiguration="MyUnsecureBindingConfig" />
   <endpoint address="mex"
             binding="mexHttpBinding"
             contract="IMetadataExchange"/>
</service>

UPDATE:

On your WCF Host application, you will need to specify the new URI to listen at. You can set up your host similar to this:

var httpsAddress = new Uri("https:// 127.0.0.1:13070/ProxySips/");
var httpAddress = new Uri("http://127.0.0.1:13070/ProxySips/");
var host = new ServiceHost(typeof(ProxySips_Wcf.Sips), 
                            new Uri[] { httpsAddress, httpAddress });
host.Open();
Derek W
  • 9,708
  • 5
  • 58
  • 67
  • Hello Derek,Thanks for your help but when I put your configuration, I have no error on execution, but nothing happens on the http endpoint. Should I create a new host service? – Bob Apr 11 '14 at 04:23
  • @Bob: I updated my answer with how to specify the multiple endpoints for your host application to listen at. Let me know either way. – Derek W Apr 11 '14 at 13:34