WCF添加HTTPS支持

时间:2017-03-28 17:56:25

标签: c# asp.net wcf

我有一个ASP.Net WCF,我试图让我的配置正确,为所有端点启用https。我不需要http,只需要https。目前它可以使用http,但现在尝试将其转换为https。

如何更改以下配置以仅允许https?

这是我的system.serviceModel

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>

    <bindings>
      <mexHttpBinding>
        <binding name="higherMessageSize_MEX" />
      </mexHttpBinding>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00"
                 receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="4194304" maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
                 messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                 useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="5242880" maxArrayLength="1000000000" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
        <binding name="basicHttpBindingConfig2" closeTimeout="00:10:00" openTimeout="00:10:00"
                 receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="4194304" maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
                 messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                 useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="5242880" maxArrayLength="1000000000" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
        <binding name="basicHttpBindingConfig3" closeTimeout="00:10:00" openTimeout="00:10:00"
                 receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="4194304" maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
                 messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                 useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="5242880" maxArrayLength="1000000000" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
        <binding name="basicHttpBindingConfig4" closeTimeout="00:10:00" openTimeout="00:10:00"
                 receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="4194304" maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
                 messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                 useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="5242880" maxArrayLength="1000000000" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>


    <services>
      <!-- Note: the service name must match the configuration name for the service implementation. -->
      <service name="Proactive_WebAPI.Services.Product"  behaviorConfiguration="ProductDataServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="http://api.proactiveclothing.com/services/Product.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig"
            contract="Proactive.Product.ProductDataService" 
            listenUri="/"/>
      </service>
      <service name="Proactive_WebAPI.Services.Media"  behaviorConfiguration="MediaContentServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="http://api.proactiveclothing.com/services/Media.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig2"
            contract="Proactive.Media.MediaContentService" 
            listenUri="/"/>
      </service>
      <service name="Proactive_WebAPI.Services.PricingAndConfiguration"  behaviorConfiguration="PricingAndConfigurationBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="http://api.proactiveclothing.com/services/PricingAndConfiguration.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig2"
            contract="Proactive.Pricing.PricingAndConfigurationService" 
            listenUri="/"/>
      </service>
      <service name="Proactive_WebAPI.Services.Inventory"  behaviorConfiguration="InventoryServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="http://api.proactiveclothing.com/services/Inventory.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig4"
            contract="Proactive.Inventory.InventoryService" 
            listenUri="/"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ProductDataServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://api.proactiveclothing.com/wsdl/ProductDataService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="MediaContentServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://api.proactiveclothing.com/wsdl/MediaContentService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="PricingAndConfigurationBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://api.proactiveclothing.com/wsdl/PricingAndConfiguration.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="InventoryServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://api.proactiveclothing.com/wsdl/InventoryService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

更新

尝试了以下配置,但无法使其正常工作:/

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>

    <bindings>
      <mexHttpBinding>
        <binding name="higherMessageSize_MEX" />
      </mexHttpBinding>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00"
                 receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
                 messageEncoding="Text" textEncoding="utf-8" 
                 useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="5242880" maxArrayLength="1000000000" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
        <binding name="basicHttpBindingConfig2" closeTimeout="00:10:00" openTimeout="00:10:00"
                 receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
                 messageEncoding="Text" textEncoding="utf-8" 
                 useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="5242880" maxArrayLength="1000000000" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
        <binding name="basicHttpBindingConfig3" closeTimeout="00:10:00" openTimeout="00:10:00"
                 receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
                 messageEncoding="Text" textEncoding="utf-8" 
                 useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="5242880" maxArrayLength="1000000000" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
        <binding name="basicHttpBindingConfig4" closeTimeout="00:10:00" openTimeout="00:10:00"
                 receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
                 messageEncoding="Text" textEncoding="utf-8" 
                 useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="5242880" maxArrayLength="1000000000" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>


    <services>
      <!-- Note: the service name must match the configuration name for the service implementation. -->
      <service name="Proactive_WebAPI.Services.Product"  behaviorConfiguration="ProductDataServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="https://api.proactiveclothing.com/services/Product.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig"
            contract="Proactive.Product.ProductDataService" 
            listenUri="/"/>
      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
      <service name="Proactive_WebAPI.Services.Media"  behaviorConfiguration="MediaContentServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="https://api.proactiveclothing.com/services/Media.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig2"
            contract="Proactive.Media.MediaContentService" 
            listenUri="/"/>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
      <service name="Proactive_WebAPI.Services.PricingAndConfiguration"  behaviorConfiguration="PricingAndConfigurationBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="https://api.proactiveclothing.com/services/PricingAndConfiguration.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig2"
            contract="Proactive.Pricing.PricingAndConfigurationService" 
            listenUri="/"/>
      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
      <service name="Proactive_WebAPI.Services.Inventory"  behaviorConfiguration="InventoryServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="https://api.proactiveclothing.com/services/Inventory.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig4"
            contract="Proactive.Inventory.InventoryService" 
            listenUri="/"/>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ProductDataServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" externalMetadataLocation="https://api.proactiveclothing.com/wsdl/ProductDataService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="MediaContentServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" externalMetadataLocation="https://api.proactiveclothing.com/wsdl/MediaContentService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="PricingAndConfigurationBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" externalMetadataLocation="https://api.proactiveclothing.com/wsdl/PricingAndConfiguration.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="InventoryServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" externalMetadataLocation="https://api.proactiveclothing.com/wsdl/InventoryService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

尝试通过C#HttpWebRequest访问服务时出现以下错误:

The remote server returned an error: (500) Internal Server Error.

0 个答案:

没有答案