WCF服务 - 协议' https'不受支持

时间:2015-04-02 07:38:51

标签: c# wcf iis ssl wcf-security

我正在使用WsHttpBinding和SSL证书开发WCF服务以确保安全性。在我的本地IIS中完美运行,但是当我发布时,我收到以下错误消息;

  

不支持协议“https”。

这是我的web.config文件..

<system.serviceModel>
<services>
  <service name="PeopleService.Service.PeopleService">
    <host>
      <baseAddresses>
        <add baseAddress="https://www.mywebsite.com/service/"/>
      </baseAddresses>
    </host>
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="BasicBinding" contract="PeopleService.Service.IPeopleService" name="BasicEndpoint"/>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="BasicBinding">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

我正在使用ServiceHost工厂添加我的端点,以便我可以从物理文件而不是从证书存储中加载SSL证书。

public class PeopleServiceHost : ServiceHost
{
    public PeopleServiceHost(params Uri[] addresses) : base(typeof(PeopleService), addresses)
    {

    }

    protected override void InitializeRuntime()
    {
        Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
        Description.Behaviors.Find<ServiceDebugBehavior>().HttpsHelpPageUrl = new Uri("https://www.mywebsite.com/service/PeopleService.svc/mex");

        ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
        metadataBehavior.HttpsGetEnabled = true;
        metadataBehavior.HttpsGetUrl = new Uri("https://www.mywebsite.com/service/PeopleService.svc/mex");
        Description.Behaviors.Add(metadataBehavior);

        var serviceCredentials = new ServiceCredentials();
        serviceCredentials.ServiceCertificate.Certificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "\\mywebsite.pfx", "password123", X509KeyStorageFlags.MachineKeySet);

        Description.Behaviors.Remove((typeof(ServiceCredentials)));
        Description.Behaviors.Add(serviceCredentials);

        base.InitializeRuntime();
    }
}

我一直试图解决这个问题好几天,但无济于事。我已经与主人联系,他们告诉我在IIS中肯定支持和启用HTTPS。

非常感谢任何帮助。感谢。

0 个答案:

没有答案