我已经创建了一个 WCF 身份验证服务并且一切正常。当我尝试对通信实现 SSL 加密时,出现以下错误:
在 https://myDomain/WebSite/MyAuthenticationSvcWrap.svc 处没有主动监听的 channel .这通常是由不正确的地址 URI 引起的。确保消息发送到的地址与服务正在监听的地址相匹配。
http服务宿主的web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="AppServiceBehaviors" name="WebSite.System.Web.ApplicationServices.AuthenticationService">
<endpoint binding="basicHttpBinding" bindingConfiguration="Binding1" bindingNamespace="http://asp.net/ApplicationServices/v200" contract="WebSite.System.Web.ApplicationServices.AuthenticationService" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="Binding1" >
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="AppServiceBehaviors">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
和客户端app.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_AuthenticationService">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mydomain/WebSite/MyAuthenticationSvcWrap.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_AuthenticationService"
contract="AuthenticationService" name="BasicHttpBinding_AuthenticationService" />
</client>
</system.serviceModel>
https服务主机:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="AppServiceBehaviors" name="WebSite.System.Web.ApplicationServices.AuthenticationService">
<endpoint binding="basicHttpBinding" bindingConfiguration="Binding1" bindingNamespace="http://asp.net/ApplicationServices/v200" contract="WebSite.System.Web.ApplicationServices.AuthenticationService" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="Binding1" >
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="AppServiceBehaviors">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
和客户端的app.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_AuthenticationService">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://mydomain/WebSite/MyAuthenticationSvcWrap.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_AuthenticationService"
contract="AuthenticationService" name="BasicHttpBinding_AuthenticationService" />
</client>
</system.serviceModel>
实际上,我已经在两个文件的 basicHttpBinding 中将元素的模式属性更改为 Transport,并将客户端端点地址从 http 更改为 https。我还必须在这里注意,通过点击 https://mydomain/WebSite/MyAuthenticationSvcWrap.svc在浏览器中找到页面并获得响应。
有人可以提出为什么会发生这种行为吗?
非常感谢
最佳答案
我终于设法解决了这个问题,尽管答案并没有使我的事情变得更好,清晰度。
解决方案是在 IIS 的 SSL 设置中勾选“需要 SSL”。这没有任何意义,因为在我看来,如果未勾选要求 SSL,则意味着 SSL 请求仍然可以以相同的方式处理。
此外,错误消息继续出现,尽管这次更容易解决。事实证明,如果安全模式设置为“传输”,我必须从元素的名称属性中省略程序集名称。换句话说,它必须与 .svc 文件中声明的服务名称完全相同。在我的例子中是 System.Web.ApplicationServices.AuthenticationService,而 WebSite.System.Web.ApplicationServices.AuthenticationService 给出了一个错误。必须相应地更改契约(Contract)属性。
但令我惊讶的不是为什么会发生这种情况,而是当模式属性设置为“Nothing”时为什么不会发生这种情况。虽然我的应用程序现在按我想要的方式工作,但我仍然想深入了解以前的问题以获得更好的理解。如果有人可以进一步提供帮助,我将不胜感激。
非常感谢。
关于asp.net - 使用 SSL 加密的 WCF 身份验证服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32473173/