Web services 如何使wcf工作web服务在https上工作?

Web services 如何使wcf工作web服务在https上工作?,web-services,wcf,Web Services,Wcf,我编写了一些工作良好的wcf web服务(restful)。 我现在需要只支持从https调用这些web服务 配置文件代码: <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior"> <host> <baseAddresses> <a

我编写了一些工作良好的wcf web服务(restful)。 我现在需要只支持从https调用这些web服务

配置文件代码:

 <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">  
    <host>  
      <baseAddresses>  
        <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>  
      </baseAddresses>  
    </host>  
    <endpoint address=""    binding="wsHttpBinding" contract="Microsoft.ServiceModel.Samples.ICalculator" />  
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />  
  </service>  
</services>  
<behaviors>  
  <serviceBehaviors>  
    <behavior name="CalculatorServiceBehavior">  
      <serviceMetadata httpGetEnabled="true"/>  
      <serviceDebug includeExceptionDetailInFaults="False"/>  
    </behavior>  
  </serviceBehaviors>  
</behaviors>  


以下是启用SSL的步骤

  • 首先创建一个自签名证书,您可以使用IIS管理器来执行此操作
  • 打开INETMGR,然后打开服务器证书,然后继续创建自签名证书,称其名称为testcertificate
现在在您的wcf配置文件中是这样的

<system.serviceModel>
    <services>
      <service name="NorthwindServices.ProductService">

        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="secureHttpBinding"
                  contract="NorthwindServices.IProducts"/>

        <endpoint address="mex"
                  binding="mexHttpsBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>      
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>          
          <serviceMetadata httpsGetEnabled="true"/>          
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>  

注意我已经改变了下面的事情

1) 在允许https请求的serviceBehaviors中,我设置了
httpsGetEnabled=“true”

2) 将
clientCredentialType
设置为“无”,以指定不执行客户端身份验证的匿名身份验证。clientCredentialType的可能值为
无、基本、摘要、Ntlm、Windows

最后,您可以在IIS中托管服务

在IIS中,右键单击站点并单击编辑绑定,现在单击添加 按钮并从添加站点绑定窗口的类型下拉列表中选择https。 从SSL证书下拉列表中选择在第一步中创建的testcertificate。单击“确定”并关闭“站点绑定”窗口

在本地主机中发布wcf