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

C# 提供的URI方案';https';无效;预期';http';。参数名称:via,c#,wcf,https,C#,Wcf,Https,我正在尝试通过basicHttpBinding创建一个WCF服务,以便通过https使用。这是我的web.config: <!-- language: xml --> <service behaviorConfiguration="MyServices.PingResultServiceBehavior" name="MyServices.PingResultService"> <endpoint address=""

我正在尝试通过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>
...

...

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

提供的URI方案“https”无效;应为“http”。参数 姓名:via


您是在Cassini(vs dev服务器)上运行此操作,还是在安装了证书的IIS上运行此操作?我过去在尝试连接devweb服务器上的安全端点时遇到过问题

这里是过去为我工作的绑定配置。它不使用
basicHttpBinding
,而是使用
wsHttpBinding
。我不知道这对你来说是不是个问题


终点呢



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

尝试在app.config上添加消息凭据,如:



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

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

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

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


参考资料


  • 要重新定义OP中的问题,请执行以下操作:

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

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

    WCFStorm教程在中解决了这个问题

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

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

    • 打开Visual Studio并向服务添加服务引用。VS将生成与服务匹配的app.config文件

    • 编辑app.config文件,以便WCFStorm可以读取该文件。请看。确保endpoint/@name和endpoint/@contract属性与wcfstorm中的值匹配

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

  • 调用该方法。这一次,方法调用将不再失败

  • 第(1)项最后一个有效的项目符号意味着删除VS在端点协定属性前面的名称空间前缀,默认情况下为“ServiceReference1”

    
    
    因此,在加载到WCFStorm中的app.config中,您希望ListsService:


    遇到了同样的问题,这就是我的解决方案最终的结果:

    
    

    我基本上用Https替换了每次出现的Http。如果愿意,您可以尝试添加这两个选项。

    添加此选项作为答案,因为您无法在注释中进行太多的格式设置。
    我也有同样的问题,只是我完全用代码创建和绑定我的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
    

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

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

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

    
    
    我们将bindings部分移出到它自己的文件中

     <bindings configSource="Bindings.config" /> 
    
    
    
    在bindings.config文件中,我们根据协议切换安全性

      <!-- None = http:// -->
      <!-- Transport = https:// -->
      <security mode="None" >
    
    
    
    现在,现场工程师只需要更改Bindings.Config文件和Client.Config,我们在其中存储每个端点的实际URL

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

    希望这有帮助。

    改变 从

    
    

    
    

    在web.config文件中。如果以编程方式而不是在web.config中执行此操作,则此更改将允许您使用https而不是http:

    new WebHttpBinding(WebHttpSecurityMode.Transport)
    

    我需要以下绑定才能正常工作:

            <binding name="SI_PurchaseRequisition_ISBindingSSL">
              <security mode="Transport">
                <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
              </security>
            </binding>
    
    
    
    我添加了一个“连接”
    <security mode="Transport">
    
    new WebHttpBinding(WebHttpSecurityMode.Transport)
    
            <binding name="SI_PurchaseRequisition_ISBindingSSL">
              <security mode="Transport">
                <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
              </security>
            </binding>
    
    var client = new MyWebService.Client(MyWebService.Client.EndpointConfiguration.MyPort, _endpointUrl);
    
    public Client(EndpointConfiguration endpointConfiguration, string remoteAddress) :
                base(Client.GetBindingForEndpoint(endpointConfiguration), 
                     new System.ServiceModel.EndpointAddress(remoteAddress))
    
    System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
    result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly;
     
    
    result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
    
    <!-- Binding settings for HTTPS endpoint -->
    <binding name="yourServiceName">
        <security mode="Transport">
            <transport clientCredentialType="None" />
            <!-- Don't use message -->
        </security>
    </binding>
    
      <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>