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

发布于 2024-08-25 07:46:22 字数 1481 浏览 5 评论 0原文

我正在尝试通过 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”。范围 名称:通过

I am trying to make a WCF service over basicHttpBinding to be used over https. Here's my 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>

I am connecting using WCFStorm which is able to retrieve all the meta data properly, but when I call the actual method I get:

The provided URI scheme 'https' is invalid; expected 'http'. Parameter
name: via

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

沉默的熊 2024-09-01 07:46:22

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

Try adding message credentials on your app.config like:

<bindings> 
<basicHttpBinding> 
<binding name="defaultBasicHttpBinding"> 
  <security mode="Transport"> 
    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> 
    <message clientCredentialType="Certificate" algorithmSuite="Default" />
  </security> 
</binding> 
</basicHttpBinding> 
</bindings> 
赴月观长安 2024-09-01 07:46:22

添加此作为答案,只是因为您无法在注释中进行太多花哨的格式化。
我遇到了同样的问题,除了我完全在代码中创建和绑定我的 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

Adding this as an answer, just since you can't do much fancy formatting in comments.
I had the same issue, except I was creating and binding my web service client entirely in code.
Reason is the DLL was being uploaded into a system, which prohibited the use of config files.

Here is the code as it needed to be updated to communicate over 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
浅笑轻吟梦一曲 2024-09-01 07:46:22

改变
from

<security mode="None">

<security mode="Transport">

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

Change
from

<security mode="None">

to

<security mode="Transport">

in your web.config file. This change will allow you to use https instead of http

柠檬色的秋千 2024-09-01 07:46:22

您是在 Cassini(相对于开发服务器)还是在安装了证书的 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" />

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

Are you running this on the Cassini (vs dev server) or on IIS with a cert installed? I have had issues in the past trying to hook up secure endpoints on the dev web server.

Here is the binding configuration that has worked for me in the past. Instead of basicHttpBinding, it uses wsHttpBinding. I don't know if that is a problem for you.

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

and the endpoint

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

Also, make sure you change the client configuration to enable Transport security.

攒眉千度 2024-09-01 07:46:22

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

我实际上是从本地 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在http和https上都有自定义绑定

I had same exception in a custom binding scenario. Anybody using this approach, can check this too.

I was actually adding the service reference from a local WSDL file. It got added successfully and required custom binding was added to config file. However, the actual service was https; not http. So I changed the httpTransport elemet as httpsTransport. This fixed the problem

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

References

  1. WCF with custombinding on both http and https
触ぅ动初心 2024-09-01 07:46:22

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

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!

盛夏已如深秋| 2024-09-01 07:46:22

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

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

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

Ran into the same issue, this is how my solution turned out at the end:

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

I basically replaced every occurrence of Http with Https. You can try adding both of them if you prefer.

始终不够 2024-09-01 07:46:22

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

new WebHttpBinding(WebHttpSecurityMode.Transport)

If you do this programatically and not in web.config its:

new WebHttpBinding(WebHttpSecurityMode.Transport)
∝单色的世界 2024-09-01 07:46:22

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

第一步是将绑定部分从 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 文件和 Client.Config(我们在其中存储每个端点的实际 URL)。

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

希望这有帮助。

Its a good to remember that config files can be split across secondary files to make config changes easier on different servers (dev/demo/production etc), without having to recompile code/app etc.
For example we use them to allow onsite engineers to make endpoint changes without actually touching the 'real' files.

First step is to move the bindings section out of the WPF App.Config into it's own separate file.

The behaviours section is set to allow both http and https (doesn't seem to have an affect on the app if both are allowed)

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

And we move the bindings section out to its own file;

 <bindings configSource="Bindings.config" /> 

In the bindings.config file we switch the security based on protocol

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

Now the on site engineers only need to change the Bindings.Config file and the Client.Config where we store the actual URL for each endpoint.

This way we can change the endpoint from http to https and back again to test the app without having to change any code.

Hope this helps.

笑忘罢 2024-09-01 07:46:22

回顾一下OP中的问题:

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

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

WCFStorm 教程在 使用 IIS 和 SSL

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

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

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

    • 编辑 app.config 文件,以便 WCFStorm 可以读取它。请参阅加载客户端 App.config 文件。确保端点/@name 和端点/@contract 属性与 wcfstorm 中的值匹配。

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

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

项目(1)最后一个项目有效意味着删除VS在端点契约属性前面添加的命名空间前缀,默认情况下为“ServiceReference1”,

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

因此在app.config中您将其加载到您想要用于 ListsService 的 WCFtorm 中:

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

To re-cap the question in the OP:

I am connecting [to a WCF service] using WCFStorm which is able to retrieve all the meta data properly, but when I call the actual method I get:

The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via

The WCFStorm tutorials addresses this issue in Working with IIS and SSL.

Their solution worked for me:

  1. To fix the error, generate a client config that matches the wcf service configuration. The easiest way to do this is with Visual Studio.

    • Open Visual Studio and add a service reference to the service. VS will generate an app.config file that matches the service

    • Edit the app.config file so that it can be read by WCFStorm. Please see Loading Client App.config files. Ensure that the endpoint/@name and endpoint/@contract attributes match the values in wcfstorm.

  2. Load the modified app.config to WCFStorm [using the Client Config toobar button].

  3. Invoke the method. This time the method invocation will no longer fail

Item (1) last bullet in effect means to remove the namespace prefix that VS prepends to the endpoint contract attribute, by default "ServiceReference1"

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

so in the app.config that you load into WCFStorm you want for ListsService:

<endpoint ... contract="ListsService" ... />
染柒℉ 2024-09-01 07:46:22

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

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

I needed the following bindings to get mine to work:

        <binding name="SI_PurchaseRequisition_ISBindingSSL">
          <security mode="Transport">
            <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
          </security>
        </binding>
机场等船 2024-09-01 07:46:22

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

wsHttpBinding is a problem because silverlight doesn't support it!

━╋う一瞬間旳綻放 2024-09-01 07:46:22

我已通过 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;

I've added a "Connected Service" to our project by Visual Studio which generated a default method to create Client.

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

This constructor inherits ClientBase and behind the scene is creating Binding by using its own method Client.GetBindingForEndpoint(endpointConfiguration):

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

This method has different settings for https service and http service.
When you want get data from http, you should use TransportCredentialOnly:

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

For https you should use Transport:

result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
一笑百媚生 2024-09-01 07:46:22

就我而言,在 web.config 中,我必须在端点定义中将绑定=“basicHttpsBinding”更改为绑定=“basicHttpBinding”,并将相对的绑定配置复制到 basicHttpBinding 部分

In my case in web.config I had to change binding="basicHttpsBinding" to binding="basicHttpBinding" in the endpoint definition and copy the relative bindingConfiguration to basicHttpBinding section

蝶舞 2024-09-01 07:46:22
<!-- Binding settings for HTTPS endpoint -->
<binding name="yourServiceName">
    <security mode="Transport">
        <transport clientCredentialType="None" />
        <!-- Don't use message -->
    </security>
</binding>
<!-- Binding settings for HTTPS endpoint -->
<binding name="yourServiceName">
    <security mode="Transport">
        <transport clientCredentialType="None" />
        <!-- Don't use message -->
    </security>
</binding>
橙味迷妹 2024-09-01 07:46:22

我的解决方案遇到了相同的错误消息,比上面的更简单,我只是将其更新为 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>

My solution, having encountered the same error message, was even simpler than the ones above, I just updated the to basicHttpsBinding>

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

And the same in the section below:

  <client>
    <endpoint address="https://s.asmx" binding="basicHttpsBinding" bindingConfiguration="ShipServiceSoap" contract="..ServiceSoap" name="ShipServiceSoap" />
    </client>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文