您可以通过使用来做到这一点多个端点。通过多个端点,您可以通过多个协议(在您的情况下为 HTTP 和 HTTPS)支持相同的服务。
所以你需要添加以下内容ServiceBehavior
:
<behavior name="MyUnsecureServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
然后是下面的Binding
:
<basicHttpBinding>
<binding name= MyUnsecureBindingConfig"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
messageEncoding="Text">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" />
<message establishSecurityContext="false" />
</security>
</basicHttpBinding>
最后是以下内容Address
配置:
<service behaviorConfiguration="MyUnsecureServiceBehavior"
name="MyUnsecureService">
<endpoint address="http://127.0.0.1:13070/ProxySips/"
binding="basicHttpBinding"
contract="ProxySips_Wcf.ISips"
bindingConfiguration="MyUnsecureBindingConfig" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
UPDATE:
On your WCF Host
应用程序中,您需要指定要侦听的新 URI。您可以像这样设置您的主机:
var httpsAddress = new Uri("https:// 127.0.0.1:13070/ProxySips/");
var httpAddress = new Uri("http://127.0.0.1:13070/ProxySips/");
var host = new ServiceHost(typeof(ProxySips_Wcf.Sips),
new Uri[] { httpsAddress, httpAddress });
host.Open();