如何使用wcf服务启用http和https?

时间:2015-10-23 21:35:46

标签: wcf http iis https web-config

我需要发布一个wcf服务,这应该通过Http和Https协议来访问。 我试图在我的服务器中配置它,但问题是只有一个协议可以工作。

有可能吗?

这是我的Web.config代码:

<bindings>
  <basicHttpBinding>
    <binding name="basicHttpBindingConfiguration">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviorConfiguration">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="ServiceBehaviorConfiguration" >
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration" name="TestSvc" contract="ServiceTest.ITest" />
  </service>
</services>

2 个答案:

答案 0 :(得分:0)

这是可能的,但在某种程度上你可能没想到。您通过HTTPS托管服务。然后在同一个池上创建另一个站点。此站点是HTTP,它只包含看起来像这样的web.config文件

document.write("  <source data-src='{% static "filename" %}' type='video/mp4' >");

现在,每当有人尝试使用HTTP站点时,都会自动重定向到HTTPS。

答案 1 :(得分:0)

尝试将多个端点用于使用basicHttpBindind的相同服务,使用一个使用wsHttpBinding

<service name="NorthwindServices.Services.CustomerService" 
                behaviorConfiguration ="ServiceBehavior">
<host>
  <baseAddresses>
    <add baseAddress="http://localhost:7741/NorthwindServices/Services
                        /CustomerService" /> 
    <add baseAddress="https://localhost:4512/Services/CustomerService" />
   </baseAddresses>
</host>

<endpoint address ="" binding="wsHttpBinding"
    contract="NorthwindServices.ServiceContracts.ICustomerService"
    bindingNamespace = "http://dotnetmentors.com/services/customer" />
<endpoint address="mex" binding="mexHttpBinding" 
            contract="IMetadataExchange"/>

<endpoint address ="" binding ="basicHttpBinding" 
    contract ="NorthwindServices.ServiceContracts.ICustomerService"
    bindingNamespace = "http://dotnetmentors.com/services/customer"  />
<endpoint address="mex" binding="mexHttpBinding" 
            contract="IMetadataExchange"/>
</service>