C# 如何设置WCF服务以在HTTPs上运行
我已经创建了一个wcf服务,希望在安全方式(https)上运行 App.configC# 如何设置WCF服务以在HTTPs上运行,c#,wcf,iis,https,C#,Wcf,Iis,Https,我已经创建了一个wcf服务,希望在安全方式(https)上运行 App.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> </appSettings> <sy
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1" behaviorConfiguration ="MyServiceTypeBehaviors">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8734/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我已尝试将基址从http
更改为https
。
我已经从IIS创建了自签名证书,并使用https端口将其绑定到
8374
尝试使用该配置。我已将绑定从BasicHttpBinding更改为BasicHttpsBinding,并添加了“serviceCredentials”部分,在该部分中,您必须从计算机上的某个存储中选择证书
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="" binding="basicHttpsBinding" contract="WcfServiceLibrary1.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceCredentials>
<serviceCertificate findValue="" storeLocation="LocalMachine" x509FindType="FindByThumbprint" storeName="My"/>
</serviceCredentials>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
</configuration>
另外,如果web服务托管在IIS中,则不需要基本地址和端口。端口绑定是从IIS管理器完成的请查看此msdn链接:。您需要执行多个步骤才能使其工作。链接在哪里?