提供的 URI 方案“https”;无效;预期是“http”。参数名称:via
我正在尝试通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
尝试在您的 app.config 上添加消息凭据,例如:
Try adding message credentials on your app.config like:
添加此作为答案,只是因为您无法在注释中进行太多花哨的格式化。
我遇到了同样的问题,除了我完全在代码中创建和绑定我的 Web 服务客户端。
原因是 DLL 被上传到系统中,从而禁止使用配置文件。
以下是需要更新才能通过 SSL 进行通信的代码...
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...
改变
from
到
web.config 文件中的 。此更改将允许您使用 https 而不是 http
Change
from
to
in your web.config file. This change will allow you to use https instead of http
您是在 Cassini(相对于开发服务器)还是在安装了证书的 IIS 上运行它?我过去在尝试连接开发 Web 服务器上的安全端点时遇到过问题。
这是过去对我有用的绑定配置。它使用
wsHttpBinding
,而不是basicHttpBinding
。我不知道这对你来说是否是一个问题。和端点
此外,请确保更改客户端配置以启用传输安全性。
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 useswsHttpBinding
. I don't know if that is a problem for you.and the endpoint
Also, make sure you change the client configuration to enable Transport security.
我在
自定义绑定
场景中遇到了同样的异常。任何使用这种方法的人也可以检查一下。我实际上是从
本地 WSDL
文件添加服务引用。它已成功添加,并且所需的自定义绑定已添加到配置文件中。然而,实际的服务是https;不是http。所以我将 httpTransport 元素更改为httpsTransport
。这解决了问题参考
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 ashttpsTransport
. This fixed the problemReferences
我遇到了与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!
遇到了同样的问题,这就是我的解决方案最后的结果:
我基本上用 Https 替换了所有出现的 Http。如果您愿意,可以尝试添加它们。
Ran into the same issue, this is how my solution turned out at the end:
I basically replaced every occurrence of Http with Https. You can try adding both of them if you prefer.
如果您以编程方式执行此操作而不是在 web.config 中执行此操作:
If you do this programatically and not in web.config its:
最好记住,配置文件可以拆分为辅助文件,以便在不同服务器(开发/演示/生产等)上更轻松地更改配置,而无需重新编译代码/应用程序等。
例如,我们使用它们来允许现场工程师进行端点更改,而无需实际接触“真实”文件。
第一步是将绑定部分从 WPF App.Config 移到它自己的单独文件中。
行为部分设置为允许 http 和 https(如果两者都允许,似乎不会对应用程序产生影响)
并且我们将绑定部分移至其自己的文件中;
在 bindings.config 文件中,我们根据协议切换安全性
现在,现场工程师只需更改 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)
And we move the bindings section out to its own file;
In the bindings.config file we switch the security based on protocol
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.
回顾一下OP中的问题:
WCFStorm 教程在 使用 IIS 和 SSL。
他们的解决方案对我有用:
项目(1)最后一个项目有效意味着删除VS在端点契约属性前面添加的命名空间前缀,默认情况下为“ServiceReference1”,
因此在app.config中您将其加载到您想要用于 ListsService 的 WCFtorm 中:
To re-cap the question in the OP:
The WCFStorm tutorials addresses this issue in Working with IIS and SSL.
Their solution worked for me:
Item (1) last bullet in effect means to remove the namespace prefix that VS prepends to the endpoint contract attribute, by default "ServiceReference1"
so in the app.config that you load into WCFStorm you want for ListsService:
我需要以下绑定才能让我的工作正常工作:
I needed the following bindings to get mine to work:
wsHttpBinding 是一个问题,因为 silverlight 不支持它!
wsHttpBinding is a problem because silverlight doesn't support it!
我已通过 Visual Studio 将“连接服务”添加到我们的项目中,它生成了创建客户端的默认方法。
该构造函数继承了ClientBase,在幕后使用自己的方法Client.GetBindingForEndpoint(endpointConfiguration)创建Binding:
该方法对https服务和http服务有不同的设置。
当你想从http获取数据时,你应该使用TransportCredentialOnly:
对于https你应该使用Transport:
I've added a "Connected Service" to our project by Visual Studio which generated a default method to create Client.
This constructor inherits ClientBase and behind the scene is creating Binding by using its own method Client.GetBindingForEndpoint(endpointConfiguration):
This method has different settings for https service and http service.
When you want get data from http, you should use TransportCredentialOnly:
For https you should use Transport:
就我而言,在 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
我的解决方案遇到了相同的错误消息,比上面的更简单,我只是将其更新为 basicHttpsBinding>
下面的部分也是如此:
My solution, having encountered the same error message, was even simpler than the ones above, I just updated the to basicHttpsBinding>
And the same in the section below: