我试图使一个WCF服务在basicHttpBinding上使用https。这是我的web.config:

<!-- language: xml -->
<service behaviorConfiguration="MyServices.PingResultServiceBehavior"
         name="MyServices.PingResultService">
    <endpoint address="" 
              binding="basicHttpBinding" 
              bindingConfiguration="defaultBasicHttpBinding"
              contract="MyServices.IPingResultService">
        <identity>
            <dns value="localhost" />
        </identity>
    </endpoint>
    <endpoint address="mex" 
              binding="mexHttpBinding" 
              contract="IMetadataExchange" />
</service>
...
<bindings>
  <basicHttpBinding>
    <binding name="defaultBasicHttpBinding">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
...
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServices.UpdateServiceBehavior">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

我使用WCFStorm连接,它能够正确检索所有元数据,但当我调用实际的方法时,我得到:

提供的URI方案'https'无效;预计“http”。参数 名称:通过


当前回答

需要记住的是,配置文件可以拆分到次要文件中,以便在不同的服务器(开发/演示/生产等)上更容易地更改配置,而不必重新编译代码/应用程序等。 例如,我们使用它们允许现场工程师在不实际接触“真实”文件的情况下进行端点更改。

第一步是将绑定部分从WPF App.Config移出到它自己的单独文件中。

行为部分被设置为允许http和https(如果两者都被允许,似乎对应用程序没有影响)

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

我们把绑定部分移到它自己的文件中;

 <bindings configSource="Bindings.config" /> 

在绑定中。配置文件基于协议进行安全切换

  <!-- None = http:// -->
  <!-- Transport = https:// -->
  <security mode="None" >

现在现场工程师只需要更改绑定。配置文件和客户端。配置中存储每个端点的实际URL。

通过这种方式,我们可以将端点从http更改为https,然后再返回来测试应用程序,而无需更改任何代码。

希望这能有所帮助。

其他回答

如果你是通过编程而不是web。配置它:

new WebHttpBinding(WebHttpSecurityMode.Transport)

wsHttpBinding是一个问题,因为silverlight不支持它!

在我的情况下,在web。我不得不改变binding="basicHttpBinding"到binding="basicHttpBinding"在端点定义和复制相对bindingConfiguration到basicHttpBinding部分

我需要以下绑定来让我的工作:

        <binding name="SI_PurchaseRequisition_ISBindingSSL">
          <security mode="Transport">
            <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
          </security>
        </binding>

尝试在app.config中添加消息凭据,如下所示:

<bindings> 
<basicHttpBinding> 
<binding name="defaultBasicHttpBinding"> 
  <security mode="Transport"> 
    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> 
    <message clientCredentialType="Certificate" algorithmSuite="Default" />
  </security> 
</binding> 
</basicHttpBinding> 
</bindings>