WCF服务的basicHttpBinding上的HTTPS

时间:2011-12-01 07:44:16

标签: c# asp.net .net wcf iis

我使用的是IIS 7.在端口号为443的情况下启用了HTTPS绑定。我有一个WCF服务作为网站下的应用程序。我正在尝试基于http://msdn.microsoft.com/en-us/library/ms729700.aspx

将HTTPS安全性引入服务(使用basicHttpBinding)

我收到以下错误 - “提供的URI方案'https'无效;预期'http'。“当我检查事件日志时,它具有如下堆栈跟踪:

Stack Trace :    at System.ServiceModel.Channels.TransportChannelFactory`1.ValidateScheme(Uri via)

at System.ServiceModel.Channels.HttpChannelFactory.ValidateCreateChannelParameters(EndpointAddress remoteAddress, Uri via)

使用basicHttpBinding使HTTPS工作所需的更改是什么?

注意:使用IIS 7中的“创建自签名证书”创建证书。

 <system.serviceModel>

  <behaviors>
<serviceBehaviors>
  <behavior name="serviceFaultBehavior">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true"/>
  </behavior>
</serviceBehaviors>
  </behaviors>

  <services>
<service name="Business.TV.Clearance.Services.ServiceHandler"
         behaviorConfiguration="serviceFaultBehavior">
  <endpoint address=""
            binding="basicHttpBinding"
            contract="Business.TV.Clearance.Services.IServiceHandler"
            bindingConfiguration="httpBinding">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
</service>

  <bindings>
<basicHttpBinding>

  <binding name="httpBinding"
           maxReceivedMessageSize="2000000"
           maxBufferSize="2000000">

    <security mode="Transport">
      <transport clientCredentialType="Windows" />
    </security>


    <readerQuotas maxDepth="2147483647"
                  maxStringContentLength="2147483647"
                  maxArrayLength="2147483647" />
  </binding>
</basicHttpBinding>
  </bindings>

   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

   <extensions>
 <behaviorExtensions>
  <add name="serviceFaultBehavior"
type="Business.TV.Clearance.Services.ServiceFaultBehaviorExtensionElement,Business.TV.Clearance.Services, Version=1.0.0.0, Culture=neutral"/>
</behaviorExtensions>
  </extensions>

</system.serviceModel>

3 个答案:

答案 0 :(得分:2)

您需要更改:

<serviceMetadata httpGetEnabled="true" />

为:

<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />

答案 1 :(得分:0)

请尝试如下所示:

<service name="UserNameWithoutSSL.UsernameWithSSLService" behaviorConfiguration="TransportWithSecurity">
  <endpoint address="" binding="basicHttpBinding" bindingConfiguration="usernameViaSSL" contract="UserNameWithoutSSL.IUsernameWithSSLService">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  <host>
    <baseAddresses>
      <add baseAddress="https://PCName/" />
    </baseAddresses>
  </host>
</service>

<basicHttpBinding>
  <binding name="usernameViaSSL">
    <security mode="TransportWithMessageCredential">
      <message clientCredentialType="UserName"/>
    </security>
  </binding>
</basicHttpBinding>

<serviceBehaviors>
  <behavior name="TransportWithSecurity">
    <serviceCredentials>
      <serviceCertificate findValue="localhost" storeLocation="LocalMachine"
        storeName="My" x509FindType="FindBySubjectName" />
      <userNameAuthentication userNamePasswordValidationMode="Windows" />
    </serviceCredentials>
    <serviceMetadata httpsGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true" />
  </behavior>
</serviceBehaviors>

现在,在虚拟目录上的IIS上,您需要映射443以接受Https流量并分配它需要用于保护传输层的证书。

答案 2 :(得分:-3)

请尝试更换以下内容,这应该可行。

原件:

<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>

替换为:

<security mode="Transport">
<transport clientCredentialType="None" />
</security>