我试图使一个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”。参数 名称:通过


当前回答

<!-- Binding settings for HTTPS endpoint -->
<binding name="yourServiceName">
    <security mode="Transport">
        <transport clientCredentialType="None" />
        <!-- Don't use message -->
    </security>
</binding>

其他回答

我在自定义绑定场景中遇到了相同的异常。任何使用这种方法的人,也可以检查这个。

我实际上是从本地WSDL文件中添加服务引用。它被成功添加,所需的自定义绑定被添加到配置文件。然而,实际的服务是https;而不是http。因此我将httpTransport元素更改为httpTransport。这就解决了问题

<system.serviceModel>
<bindings>

  <customBinding>
    <binding name="MyBindingConfig">

      <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
        messageVersion="Soap11" writeEncoding="utf-8">
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      </textMessageEncoding>

      <!--Manually changed httpTransport to httpsTransport-->
      <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
        maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
        bypassProxyOnLocal="false" 
        decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
        keepAliveEnabled="true" maxBufferSize="65536" 
        proxyAuthenticationScheme="Anonymous"
        realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
        useDefaultWebProxy="true" />
    </binding>
  </customBinding>

</bindings>

<client>
  <endpoint address="https://mainservices-certint.mycompany.com/Services/HRTest"
    binding="customBinding" bindingConfiguration="MyBindingConfig"
    contract="HRTest.TestWebserviceManagerImpl" name="TestWebserviceManagerImpl" />
</client>


</system.serviceModel>

参考文献

WCF与自定义绑定在http和https

添加这个作为答案,因为你不能在注释中做太多花哨的格式。 我也遇到了同样的问题,只不过我完全用代码创建和绑定了我的web服务客户端。 原因是DLL被上传到一个系统,这禁止使用配置文件。

下面是代码,因为它需要更新以通过SSL通信…

Public Function GetWebserviceClient() As WebWorker.workerSoapClient
    Dim binding = New BasicHttpBinding()
    binding.Name = "WebWorkerSoap"
    binding.CloseTimeout = TimeSpan.FromMinutes(1)
    binding.OpenTimeout = TimeSpan.FromMinutes(1)
    binding.ReceiveTimeout = TimeSpan.FromMinutes(10)
    binding.SendTimeout = TimeSpan.FromMinutes(1)

    '// HERE'S THE IMPORTANT BIT FOR SSL
    binding.Security.Mode = BasicHttpSecurityMode.Transport

    Dim endpoint = New EndpointAddress("https://myurl/worker.asmx")

    Return New WebWorker.workerSoapClient(binding, endpoint)
End Function

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

new WebHttpBinding(WebHttpSecurityMode.Transport)

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

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

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

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

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

 <bindings configSource="Bindings.config" /> 

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

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

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

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

希望这能有所帮助。

I had the EXACT same issue as the OP. My configuration and situation were identical. I finally narrowed it down to being an issue in WCFStorm after creating a service reference in a test project in Visual Studio and confirming that the service was working. In Storm you need to click on the "Config" settings option (NOT THE "Client Config"). After clicking on that, click on the "Security" tab on the dialog that pops up. Make sure "Authentication Type" is set to "None" (The default is "Windows Authentication"). Presto, it works! I always test out my methods in WCFStorm as I'm building them out, but have never tried using it to connect to one that has already been set up on SSL. Hope this helps someone!