c# - WCF 服务的 basicHttpBinding 上的 HTTPS

标签 c# asp.net .net wcf iis

我正在使用 IIS 7。它启用了 HTTPS 绑定(bind),端口号为 443。我在网站下有一个 WCF 服务作为应用程序。我正在尝试基于 http://msdn.microsoft.com/en-us/library/ms729700.aspx 向服务(使用 basicHttpBinding)引入 HTTPS 安全性

我收到以下错误 - “提供的 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>

最佳答案

你需要改变:

<serviceMetadata httpGetEnabled="true" />

到:

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

关于c# - WCF 服务的 basicHttpBinding 上的 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8337978/

相关文章:

ASP.NET 动态用户控件

.net - NHibernate 自定义 SQL 对象创建

.net - Dotnetnuke版本确定

c# - 在 C# 中显示引用地址(调试 WCF)

c# - 如何使我的代码诊断语法节点操作对已关闭的文件起作用?

javascript - 单击 ASP.net 控件时如何使我的网页运行 JavaScript 代码?

javascript 无法读取 null 的属性 'style'

c# - WER 报告的神秘 IL 偏移量

c# - 什么时候应该提供接口(interface)的通用和非通用版本?

c# - Activator.CreateInstance(Type) 作为接口(interface)返回 null