gpt4 book ai didi

c# - WebHttpBinding 与 Http 和 Https

转载 作者:可可西里 更新时间:2023-11-01 08:28:33 25 4
gpt4 key购买 nike

我正在尝试为网站使用 https 和 http。该网站具有充当 REST 服务并从 JavaScript 调用的 .svc 文件。

我的配置:

<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups">
<endpoint address="" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" bindingConfiguration="httpWebBinding" contract="MyService.Lookups" >
</endpoint>
<endpoint address="" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" bindingConfiguration="httpsWebBinding" contract="MyService.Lookups" >
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="httpsWebBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
<binding name="httpWebBinding">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>

浏览 https://myserver/services/Lookups.svc/Hello

找不到与具有绑定(bind) WebHttpBinding 的端点的方案 http 相匹配的基址。注册的基地址方案是 [https]

浏览 http://myserver/services/Lookups.svc/Hello

找不到与具有绑定(bind) WebHttpBinding 的端点的方案 https 相匹配的基址。注册的基地址方案是 [http]

如果我删除任何一个端点,它就会起作用。删除使用 bindingConfiguration="httpWebBinding" 配置的端点的示例适用于 HTTPS,

如何让它与 HTTP 和 HTTPS 一起工作?到目前为止,我可以通过删除一个端点来使用 http 或 https。

引用How can I combine the WCF services config for both http and https in one web.config?How do you setup HTTP and HTTPS WCF 4 RESTful services?

Note: In IIS, it is two web sites one listen on http and another on https. Both sharing same code in physical folder

更新:截至目前,我删除了端点并且它有效。但我担心的是删除配置了 behaviorConfiguration 的端点对我来说并不是很好的解决方案。

这适用于 http 和 https

  <services>
<service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups">

</service>
</services>

最佳答案

我已经重新创建了您的场景并使用您的 web.config 为我的测试服务配置端点。您的配置没有问题并且工作正常。不适合您的部分可能是您在 IIS 中的 https 配置。确保您已启用对服务的 https 访问。如果您使用 Visual Studio 中的 IISExpress 对其进行测试,则左键单击您的项目并在属性窗口(查看 -> 属性窗口)中选择 SSL Enabled = True。

关于c# - WebHttpBinding 与 Http 和 Https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36578047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com