gpt4 book ai didi

.net - 如何将单个 WCF 服务配置为具有多个 HTTP 和 HTTPS 端点?

转载 作者:行者123 更新时间:2023-12-04 02:41:22 26 4
gpt4 key购买 nike

我想要做的是让 SINGLE WCF 服务在作为 HTTP 方案的开发环境中工作,并且让 SAME 服务在作为 HTTPS 方案的生产环境中工作。如果我删除两个 Https 端点(后缀为“Https”),它可以在开发环境中工作;同样,如果我只删除两个 Http 端点,那么它可以在生产环境中工作。如果可能,我想在 web.config 中包含所有四个端点。

我的端点定义如下:

<endpoint address="/Web" 
behaviorConfiguration="AjaxBehavior"
binding="wsHttpBinding"
bindingConfiguration="web"
name="Web"
contract="Service" />
<endpoint address="/Custom"
binding="customBinding"
bindingConfiguration="custom"
name="Custom"
contract="Service" />
<endpoint
address="/WebHttps"
behaviorConfiguration="AjaxBehavior"
binding="wsHttpBinding"
bindingConfiguration="webHttps"
name="WebHttps"
contract="Service" />
<endpoint address="/CustomHttps"
binding="customBinding"
bindingConfiguration="customHttps"
name="CustomHttps"
contract="Service" />

已编辑:我正在编辑我的问题以添加我遇到的错误以及绑定(bind)部分(如下)。很抱歉问题的新长度。

错误是:
“找不到与绑定(bind) WebHttpBinding 的端点的方案 http 匹配的基地址。注册的基地址方案是 [https]。”

此外,生产站点设置为“需要 SSL”。那是不能改变的。

绑定(bind)配置为:
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>

<bindings>
<customBinding>
<binding name="custom">
<textMessageEncoding>
<readerQuotas maxDepth="7000000" maxStringContentLength="7000000"
maxArrayLength="7000000" maxBytesPerRead="7000000"
maxNameTableCharCount="7000000" />
</textMessageEncoding>

<httpTransport maxBufferPoolSize="7000000" maxReceivedMessageSize="7000000"
maxBufferSize="7000000" />
</binding>
<binding name="customHttps">
<textMessageEncoding>
<readerQuotas maxDepth="7000000" maxStringContentLength="7000000"
maxArrayLength="7000000" maxBytesPerRead="7000000"
maxNameTableCharCount="7000000" />
</textMessageEncoding>

<httpsTransport maxBufferPoolSize="7000000" maxReceivedMessageSize="7000000"
maxBufferSize="7000000" />

</binding>
</customBinding>

<webHttpBinding>
<binding name="web" maxBufferPoolSize="70000000"
maxReceivedMessageSize="70000000">
<readerQuotas maxDepth="70000000" maxStringContentLength="70000000"
maxArrayLength="70000000" maxBytesPerRead="70000000"
maxNameTableCharCount="70000000" />
<security mode="None" />
</binding>

<binding name="webHttps" maxBufferPoolSize="70000000"
maxReceivedMessageSize="70000000">

<readerQuotas maxDepth="70000000" maxStringContentLength="70000000"
maxArrayLength="70000000" maxBytesPerRead="70000000"
maxNameTableCharCount="70000000" />

<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

有任何想法吗?

最佳答案

跟着这些步骤-

1)为服务编写两个端点,一个用于http,另一个用于https。

<services>
<service behaviorConfiguration="MyServiceBehavior" name="JK.MyService">

<endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="JK.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>

<endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBindingHTTPS" contract="JK.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>

</service>
</services>

2) 在 serviceBehaviors 中同时启用 httpGetEnabled="True"httpsGetEnabled="true"。
<behaviors>

<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>

<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>

</behaviors>

3)为http和https编写两个绑定(bind)配置。对于 http 给定安全模式 =“None”,对于 https 给定模式 =“Transport”。
<bindings>
<webHttpBinding>

<binding name="webBinding">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>

<binding name="webBindingHTTPS">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>

</webHttpBinding>
</bindings>

检查此 link

关于.net - 如何将单个 WCF 服务配置为具有多个 HTTP 和 HTTPS 端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3824419/

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