HTTPS在basicHttpBinding为WCF服务
本文关键字:WCF 服务 basicHttpBinding HTTPS | 更新日期: 2023-09-27 18:16:13
我使用IIS 7。启用HTTPS绑定,端口号为443。我有一个WCF服务作为网站下的应用程序。我正在尝试引入HTTPS安全服务(与basicHttpBinding)基于http://msdn.microsoft.com/en-us/library/ms729700.aspx
我得到以下错误- "提供的URI方案'https'无效;预计"http"。"。当我检查事件日志时,它的堆栈跟踪如下:
Stack Trace : at System.ServiceModel.Channels.TransportChannelFactory`1.ValidateScheme(Uri via)
at System.ServiceModel.Channels.HttpChannelFactory.ValidateCreateChannelParameters(EndpointAddress remoteAddress, Uri via)
什么是需要改变,使其工作在HTTPS与basicHttpBinding?
注意:在IIS 7中使用"创建自签名证书"创建证书。
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="serviceFaultBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Business.TV.Clearance.Services.ServiceHandler"
behaviorConfiguration="serviceFaultBehavior">
<endpoint address=""
binding="basicHttpBinding"
contract="Business.TV.Clearance.Services.IServiceHandler"
bindingConfiguration="httpBinding">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
<bindings>
<basicHttpBinding>
<binding name="httpBinding"
maxReceivedMessageSize="2000000"
maxBufferSize="2000000">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<extensions>
<behaviorExtensions>
<add name="serviceFaultBehavior"
type="Business.TV.Clearance.Services.ServiceFaultBehaviorExtensionElement,Business.TV.Clearance.Services, Version=1.0.0.0, Culture=neutral"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
您需要更改:
<serviceMetadata httpGetEnabled="true" />
:
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
请尝试如下:
<service name="UserNameWithoutSSL.UsernameWithSSLService" behaviorConfiguration="TransportWithSecurity">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="usernameViaSSL" contract="UserNameWithoutSSL.IUsernameWithSSLService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://PCName/" />
</baseAddresses>
</host>
</service>
<basicHttpBinding>
<binding name="usernameViaSSL">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
<serviceBehaviors>
<behavior name="TransportWithSecurity">
<serviceCredentials>
<serviceCertificate findValue="localhost" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName" />
<userNameAuthentication userNamePasswordValidationMode="Windows" />
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
现在,在虚拟目录上的IIS上,您需要映射443以接受Https通信,并分配用于保护传输层的证书。
请尝试替换下面的内容,这应该可以工作。
原始:<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
替换为:
<security mode="Transport">
<transport clientCredentialType="None" />
</security>