【问题标题】:The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via提供的 URI 方案“https”无效;预期的“http”。参数名称:via
【发布时间】:2011-01-27 00:11:45
【问题描述】:

我正在尝试通过 basicHttpBinding 创建 WCF 服务以通过 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”。范围 名称:通过

【问题讨论】:

  • 在德语中,错误消息显示为“Das bereitgestellte URI-Schema "https" ist ungültig; erwartet wurde "http"。参数名称:via”,以防有人在谷歌搜索这个。

标签: c# wcf https


【解决方案1】:

尝试在您的 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> 

【讨论】:

  • 感谢您对 OP 的回复;我遇到了同样的问题,将 标签的模式从默认的“无”更改为“传输”修复了它。
  • 除了 块,由于某种原因被 IIS6 拒绝,这很好用。
  • 将相同的配置复制到我的项目中,但没有任何效果。我错过了什么要补充的吗?
  • 非常感谢。我尝试了几种在网上找到的解决方案,但都没有奏效。这个很完美。
【解决方案2】:

添加这个作为答案,只是因为你不能在 cmets 中做太多花哨的格式化。
我遇到了同样的问题,除了我完全在代码中创建和绑定我的 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 服务创建类的?
  • 它有效!我在 C# 中遇到了同样的问题。只需复制粘贴即可解决问题。
  • @kaiyaq - 我仍然可以使用所有标准的东西很好地连接到服务进行开发,让 VS 为我创建类,然后编译到 DLL 中。只是在运行时我无法上传包含所有连接信息的配置文件。
  • BasicHttpBinding 通过使用 System.ServiceModel 存在;仅供参考未来的读者。
  • 7 年后,依然很棒
【解决方案3】:

改变 来自

<security mode="None">

<security mode="Transport">

在您的 web.config 文件中。此更改将允许您使用 https 而不是 http

【讨论】:

    【解决方案4】:

    您是在 Cassini(vs 开发服务器)上运行它还是在安装了证书的 IIS 上运行它?过去我在尝试连接开发 Web 服务器上的安全端点时遇到过问题。

    这是过去对我有用的绑定配置。它使用wsHttpBinding 而不是basicHttpBinding。不知道是不是你的问题。

    <!-- Binding settings for HTTPS endpoint -->
    <binding name="WsSecured">
        <security mode="Transport">
            <transport clientCredentialType="None" />
            <message clientCredentialType="None"
                negotiateServiceCredential="false"
                establishSecurityContext="false" />
        </security>
    </binding>
    

    和端点

    <endpoint address="..." binding="wsHttpBinding"
        bindingConfiguration="WsSecured" contract="IYourContract" />
    

    另外,请确保更改客户端配置以启用传输安全性。

    【讨论】:

    • 安装了自签名证书的本地 IIS 7
    • “另外,请确保更改客户端配置以启用传输安全性。” - 好建议。太容易被忽视,WCF 不会在其错误中提供线索。
    • 无效的协商服务凭据和建立安全上下文
    【解决方案5】:

    我在custom binding 场景中遇到了同样的异常。任何使用这种方法的人,也可以检查一下。

    我实际上是从local WSDL 文件添加服务引用。它已成功添加,并且所需的自定义绑定已添加到配置文件中。但是,实际的服务是 https;不是http。所以我将 httpTransport 元素更改为httpsTransport。这解决了问题

    <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>
    

    参考文献

    1. WCF with custombinding on both http and https

    【讨论】:

      【解决方案6】:

      我遇到了与 OP 完全相同的问题。我的配置和情况是相同的。在 Visual Studio 的测试项目中创建服务引用并确认服务正常工作后,我最终将其缩小为 WCFStorm 中的一个问题。在 Storm 中,您需要单击“配置”设置选项(不是“客户端配置”)。单击该按钮后,单击弹出对话框中的“安全”选项卡。确保“身份验证类型”设置为“无”(默认为“Windows 身份验证”)。很快,它的工作原理!在构建方法时,我总是在 WCFStorm 中测试我的方法,但从未尝试使用它连接到已经在 SSL 上设置的方法。希望这对某人有帮助!

      【讨论】:

      • 我遇到了同样的问题,但是我使用“用户名/密码验证”输入了错误的密码。原来,如果你更改密码,你需要点击服务的 URL 和工具栏上的“刷新”按钮才能接受它。
      【解决方案7】:

      遇到了同样的问题,最后我的解决方案是这样的:

              <basicHttpsBinding>
                  <binding name="VerificationServicesPasswordBinding">
                    <security mode="Transport">
                    </security>
                  </binding>
                  <binding name="VerificationServicesPasswordBinding1" />
              </basicHttpsBinding>
      

      我基本上用 Https 替换了每次出现的 Http。如果您愿意,可以尝试同时添加它们。

      【讨论】:

      • 应该注意basicHttpsBinding是4.5及更新的。
      【解决方案8】:

      如果您以编程方式而不是在 web.config 中执行此操作:

      new WebHttpBinding(WebHttpSecurityMode.Transport)
      

      【讨论】:

      • 太棒了。我一直讨厌 .exe.config 文件,而是通过代码来做所有事情。这解决了我的问题。
      【解决方案9】:

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

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

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

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

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

       <bindings configSource="Bindings.config" /> 
      

      在 bindings.config 文件中我们根据协议切换安全性

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

      现在现场工程师只需要更改 Bindings.Config 文件和我们存储每个端点的实际 URL 的 Client.Config。

      这样我们可以将端点从 http 更改为 https 并再次返回以测试应用程序,而无需更改任何代码。

      希望这会有所帮助。

      【讨论】:

        【解决方案10】:

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

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

        【讨论】:

          【解决方案11】:

          在 OP 中重新总结问题:

          我正在使用能够正确检索所有元数据的 WCFStorm 连接 [到 WCF 服务],但是当我调用实际方法时,我得到:

          提供的 URI 方案“https”无效;预期的“http”。参数名称:via

          WCFStorm 教程在Working with IIS and SSL 中解决了这个问题。

          他们的解决方案对我有用:

          1. 要修复错误,请生成与 wcf 服务配置匹配的客户端配置。最简单的方法是使用 Visual Studio。

            • 打开 Visual Studio 并添加对服务的服务引用。 VS会生成一个匹配服务的app.config文件

            • 编辑 app.config 文件,以便 WCFStorm 可以读取它。请参阅Loading Client App.config files。确保 endpoint/@name 和 endpoint/@contract 属性与 wcfstorm 中的值匹配。

          2. 将修改后的 app.config 加载到 WCFStorm [使用客户端配置工具栏按钮]。

          3. 调用方法。这次方法调用将不再失败

          Item (1) last bullet in effect 意味着 移除 VS 附加到端点契约属性的命名空间前缀,默认为“ServiceReference1”

          <endpoint ... contract="ServiceReference1.ListsService" ... />
          

          所以在你加载到 WCFStorm 的 app.config 中你想要 ListsService:

          <endpoint ... contract="ListsService" ... />
          

          【讨论】:

            【解决方案12】:

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

            【讨论】:

            • 供参考:Windows Phone 7、Windows Phone 8 或 WinRT 都没有。
            • 我为silverlight添加了答案
            【解决方案13】:

            我已经通过 Visual Studio 在我们的项目中添加了一个“连接服务”,它生成了一个默认方法来创建客户端。

            var client = new MyWebService.Client(MyWebService.Client.EndpointConfiguration.MyPort, _endpointUrl);
            

            这个构造函数继承了ClientBase,并在幕后使用自己的方法Client.GetBindingForEndpoint(endpointConfiguration)来创建Binding:

            public Client(EndpointConfiguration endpointConfiguration, string remoteAddress) :
                        base(Client.GetBindingForEndpoint(endpointConfiguration), 
                             new System.ServiceModel.EndpointAddress(remoteAddress))
            

            此方法对https服务和http服务有不同的设置。 当你想从 http 获取数据时,你应该使用 TransportCredentialOnly

            System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
            result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly;
             
            

            对于 https,您应该使用 Transport

            result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
            

            【讨论】:

              【解决方案14】:
              <!-- Binding settings for HTTPS endpoint -->
              <binding name="yourServiceName">
                  <security mode="Transport">
                      <transport clientCredentialType="None" />
                      <!-- Don't use message -->
                  </security>
              </binding>
              

              【讨论】:

                【解决方案15】:

                我的解决方案,遇到了同样的错误信息,比上面的更简单,我只是更新了 basicHttpsBinding>

                  <bindings>
                    <basicHttpsBinding>
                    <binding name="ShipServiceSoap" maxBufferPoolSize="512000" maxReceivedMessageSize="512000" />
                    </basicHttpsBinding>
                    </bindings>
                

                下面的部分也一样:

                  <client>
                    <endpoint address="https://s.asmx" binding="basicHttpsBinding" bindingConfiguration="ShipServiceSoap" contract="..ServiceSoap" name="ShipServiceSoap" />
                    </client>
                

                【讨论】:

                  【解决方案16】:

                  如果您在将服务引用添加到调用 https 服务的应用程序时不小心,则可能会发生此错误

                  例如,如果您删除了以前的服务引用,它曾经是 http://example.com/Service.svc,然后重新创建它现在是 https://example.com/service.svc

                  如果在重新创建服务引用之前不小心删除了 web.config 中的旧客户端和绑定,它将创建 BasicHttpBinding_IService1 而不是 BasicHttpBinding_IService。然后,当您将应用程序部署到实际服务器时,它会说“https 是无效的预期 http”,因为它正在寻找 BasicHttpBinding_IService1 而不是 BasicHttpBinding_IService。

                  与此同时,您尝试了上述所有建议,但没有结果。

                  只是想我会把它扔在那里。

                  【讨论】:

                    【解决方案17】:

                    在 web.config 中,我必须在端点定义中将 binding="basicHttpsBinding" 更改为 binding="basicHttpBinding" 并将相关 bindingConfiguration 复制到 basicHttpBinding 部分

                    【讨论】:

                      猜你喜欢
                      • 1970-01-01
                      • 2021-11-03
                      • 1970-01-01
                      • 2012-07-18
                      • 2015-11-19
                      • 2012-02-19
                      • 2010-12-14
                      • 1970-01-01
                      • 2012-04-09
                      相关资源
                      最近更新 更多