C# WCF 异常:找不到与端点的方案 http 匹配的基地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19918213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF Exception: Could not find a base address that matches scheme http for the endpoint
提问by RealWillyWoka
I'm trying to host a WCF web service on a separate Website in IIS with https at 443 as the only binding.
我正在尝试在 IIS 中的单独网站上托管 WCF Web 服务,并将 https 443 作为唯一绑定。
The following configurations works well when I use it in a website which uses both the bindings (http(80) / https(443)). If I remove the http binding, it starts throwing the following error.
当我在同时使用绑定 (http(80) / https(443)) 的网站中使用它时,以下配置效果很好。如果我删除 http 绑定,它会开始抛出以下错误。
Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [https].
无法找到与具有绑定 BasicHttpBinding 的端点的方案 http 匹配的基地址。注册的基地址方案是 [https]。
How do I make it work in an IIS website with https binding only?
如何使其在仅具有 https 绑定的 IIS 网站中工作?
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="defaultBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/ERPService/retailPayment.svc"
binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding"
contract="RetailPaymentService.RetailPayment.SVRetailPaymentService" name="EnterpriseRetailPayment" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyEndPointBehavior">
<!--<SchemaValidator enabled="true"/>-->
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="SettlementSalesCollection.SaleItemService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint behaviorConfiguration="MyEndPointBehavior" binding="basicHttpBinding"
name="SettlementSalesCollection"
contract="SettlementSalesCollection.CITransactionSettlementListenerService" />
<endpoint name="mexEndpoint" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<extensions>
<behaviorExtensions>
<add name="SchemaValidator"
type="SettlementSalesCollection.SchemaValidation.SchemaValidationBehavior+CustomBehaviorSection, SettlementSalesCollectionService, Version=1.0.0.0, Culture=neutral" />
</behaviorExtensions>
</extensions>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
采纳答案by Szymon
Your configuration should look similar to that. You may have to change <transport clientCredentialType="None" proxyCredentialType="None" />
depending on your needs for authentication. The config below doesn't require any authentication.
您的配置应该与此类似。您可能<transport clientCredentialType="None" proxyCredentialType="None" />
需要根据身份验证的需要进行更改。下面的配置不需要任何身份验证。
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfiguration">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="XXX">
<endpoint
name="AAA"
address=""
binding="basicHttpBinding"
bindingConfiguration="basicHttpBindingConfiguration"
contract="YourContract" />
</service>
<services>
That will allow a WCF service with basicHttpBinding
to use HTTPS.
这将允许 WCF 服务basicHttpBinding
使用 HTTPS。
回答by A P
I tried the binding according to the answer by @Szymon but It did not work for me. I tried basicHttpsBindingwhich is new in .net 4.5 and It solved the issue. Here is the complete configuration that works for me.
我根据@Szymon 的回答尝试了绑定,但它对我不起作用。我尝试了 .net 4.5 中新增的basicHttpsBinding,它解决了这个问题。这是对我有用的完整配置。
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpsBinding>
<binding name="basicHttpsBindingForYourService">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"/>
</security>
</binding>
</basicHttpsBinding>
</bindings>
<services>
<service name="YourServiceName">
<endpoint address="" binding="basicHttpsBinding" bindingName="basicHttpsBindingForYourService" contract="YourContract" />
</service>
</services>
</system.serviceModel>
FYI: My application's target framework is 4.5.1. IIS web site that I created to deploy this wcf service only has https binding enabled.
仅供参考:我的应用程序的目标框架是 4.5.1。我为部署此 wcf 服务而创建的 IIS 网站仅启用了 https 绑定。
回答by JsonW
My issue was caused by missing bindings in IIS, in the left tree view "Connections", under Sites, Right click on your site > edit bindings > add > https
我的问题是由 IIS 中缺少绑定引起的,在左侧树视图“连接”中,在站点下,右键单击您的站点 > 编辑绑定 > 添加 > https
Choose 'IIS Express Development Certificate' and set port to 443 Then I added another binding to the webconfig:
选择“IIS Express Development Certificate”并将端口设置为 443 然后我向 webconfig 添加了另一个绑定:
<endpoint address="wsHttps" binding="wsHttpBinding" bindingConfiguration="DefaultWsHttpBinding" name="Your.bindingname" contract="Your.contract" />
<endpoint address="wsHttps" binding="wsHttpBinding" bindingConfiguration="DefaultWsHttpBinding" name="Your.bindingname" contract="Your.contract" />
Also added to serviceBehaviours:
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
还添加到 serviceBehaviours:
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
And eventually it worked, none of the solutions I checked on stackoverflow for this error was applicable to my specific scenario, so including here in case it helps others
最终它奏效了,我在 stackoverflow 上针对此错误检查的所有解决方案都不适用于我的特定场景,因此包括在此处以防对其他人有帮助
回答by Simon_Weaver
You can get this if you ONLY configure https
as a site binding inside IIS.
如果您仅https
在 IIS 中配置为站点绑定,则可以获得此信息。
You need to add http(80)
as well as https(443)
- at least I did :-)
您需要添加http(80)
以及https(443)
- 至少我做了:-)
回答by housten
In my case the binding name in under protocol mapping did not match the binding name on the endpoint. They match in the example below.
在我的情况下,协议映射下的绑定名称与端点上的绑定名称不匹配。它们在下面的示例中匹配。
<endpoint address="" binding="basicHttpsBinding" contract="serviceName" />
and
和
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
回答by Mandi
My issue was also caused by missing https binding in IIS: Selected default website > On the far right pane selected Bindings > add > https
我的问题也是由 IIS 中缺少 https 绑定引起的:选择默认网站 > 在最右侧窗格中选择绑定 > 添加 > https
Choose 'IIS Express Development Certificate' and set port to 443
选择“IIS Express 开发证书”并将端口设置为 443
回答by Prabaldeep Gupta
Open IIS And right click on Default App Pool and Add Binding to make application work with HTTPS protocol.
打开 IIS 并右键单击默认应用程序池并添加绑定以使应用程序使用 HTTPS 协议。
type : https
类型:https
IP address : All unassigned
IP地址:全部未分配
port no : 443
端口号:443
SSL Certificate : WMSVC
SSL 证书:WMSVC
then
然后
Click on and restart IIS
单击并重新启动 IIS
Done
完毕
回答by Ketaki More
In my case this fixed the issue
在我的情况下,这解决了问题
- Go to Project Properties by clicking F4 on the project name
- Set SSLEnabled = true
- 通过单击项目名称上的 F4 转到项目属性
- 设置 SSLEnabled = true