Wcf HTTP and HTTPS on the same host/port

后端 未结 1 1513
一整个雨季
一整个雨季 2021-01-25 19:16

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:
相关标签:
1条回答
  • 2021-01-25 19:58

    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();
    
    0 讨论(0)
提交回复
热议问题