【发布时间】:2019-02-26 10:19:17
【问题描述】:
这个话题在这里讨论了好几次,但即使在阅读了微软文档https://docs.microsoft.com/en-us/dotnet/framework/wcf/configuring-services-using-configuration-files和How can I combine the WCF services config for both http and https in one web.config?之后
我仍然不太了解 WCF 服务的所有属性是如何工作的,并且无法让我的服务支持这两种协议。
我可以让服务支持 HTTP 或 HTTPS 都没有问题,这里的问题是让服务自己选择正确的协议。
关键点是第一个端点上的绑定协议,像下面显示的任何其他更改都没有影响。
App.config-
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
绑定 -
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AccountServicePortSoap11"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message algorithmSuite="Default" />
</security>
</binding>
<binding name="AccountServicePortSoap22" />
<security mode="Transport">
<transport clientCredentialType="Window" proxyCredentialType="None" realm=""/>
<message algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
结束点-
<client>
<endpoint address="" bindingConfiguration="AccountServicePortSoap11" binding="basicHttpBinding" contract="AccountServiceRef.AccountServicePort" name="AccountServicePortSoap11" />
<endpoint address="" bindingConfiguration="AccountServicePortSoap22" binding="basicHttpBinding" contract="AccountServiceRef.AccountServicePort" name="AccountServicePortSoap22" />
</client>
App.config 的其余部分
<appSettings>
<add key="defaultServer" value="http://**.**.**.**:80 " />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DocumentFormat.OpenXml" publicKeyToken="******" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.1.0" newVersion="2.8.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我尝试过的更改-
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" bindingConfiguration="AccountServicePortSoap22"/>
<add scheme="https" binding="basicHttpBinding" bindingConfiguration="AccountServicePortSoap11"/>
</protocolMapping>
<services>
<service behaviorConfiguration="MyServiceBehavior" name="com.advantage.online.store.accountservice" >
<endpoint address="" binding="basicHttpBinding" contract="AccountServiceRef.AccountServicePort" name="AccountServicePortSoap11" />
<endpoint address="" binding="basicHttpBinding" contract="AccountServiceRef.AccountServicePort" name="AccountServicePortSoap22" />
</service>
</services>
【问题讨论】: