简体   繁体   English

具有SSL加密的WCF身份验证服务

[英]WCF Authentication Service with SSL encryption

I have created a WCF authentication service and all works well. 我已经创建了WCF身份验证服务,并且一切正常。 When I am trying to implement SSL encryption to the communication, I get the following error: 当我尝试对通信实施SSL加密时,出现以下错误:

There was no channel actively listening at https://myDomain/WebSite/MyAuthenticationSvcWrap.svc . 没有频道正在https://myDomain/WebSite/MyAuthenticationSvcWrap.svc上积极监听。 This is often caused by an incorrect address URI. 这通常是由不正确的地址URI引起的。 Ensure that the address to which the message is sent matches an address on which a service is listening. 确保将消息发送到的地址与正在侦听服务的地址匹配。

The web.config of the http service host: 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>

and client app.config: 和客户端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>

The https service host: 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>

and app.config of client: 和客户端的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>

Actually I have changed the mode attribute of the element to Transport in the basicHttpBinding of both files and also changed the client endpoint address from http to https. 实际上,我已经在两个文件的basicHttpBinding中将元素的mode属性更改为Transport,并且还将客户端端点地址从http更改为https。 I must also note here that by hitting https://mydomain/WebSite/MyAuthenticationSvcWrap.svc in a browser finds the page and gets a response. 我在这里还必须注意,通过在浏览器中点击https://mydomain/WebSite/MyAuthenticationSvcWrap.svc可以找到页面并获得响应。

Can anybody suggest why this behaviour might be happening? 有人可以建议为什么会发生这种现象吗?

Thanks alot 非常感谢

I finally managed to resolve the issue, although the answer doesn't make things any better for me, clarity-wise. 我终于设法解决了这个问题,尽管答案并不能使我感到更好。

The solution was to tick "Require SSL" at SSL Settings in IIS. 解决方案是在IIS的SSL设置中勾选“需要SSL”。 It doesn't make any sense because the way I perceive it, if Require SSL is not ticked, means that an SSL request can still be handled the same way. 这没有任何意义,因为如果未选中“需要SSL”,则我的理解方式意味着仍可以以相同方式处理SSL请求。

Furthermore, the error messages continued, although this time were easier to resolve. 此外,尽管这次更容易解决,但错误消息仍在继续。 It proved out that if the Security mode was set to 'Transport', I had to omit the Assembly name from the name attribute of the element. 事实证明,如果将安全模式设置为“传输”,则必须从元素的name属性中省略程序集名称。 In other words, it had to be exactly the same with the service name declared in the .svc file. 换句话说,它必须与.svc文件中声明的服务名称完全相同。 In my case System.Web.ApplicationServices.AuthenticationService, while WebSite.System.Web.ApplicationServices.AuthenticationService was giving an error. 在我的情况下,System.Web.ApplicationServices.AuthenticationService,而WebSite.System.Web.ApplicationServices.AuthenticationService给出了错误。 The contract attribute had to be changed accordingly. 合同属性必须相应地更改。

What surprises me though is not why this happened but why this did not happen when the mode attribute was set to 'Nothing'. 令我惊讶的不是为什么发生这种情况,而是当mode属性设置为“ Nothing”时为什么没有发生这种情况。 Although my application now works the way I want, I would still like to gain insight to the previous issues for the shake of gaining a better understanding. 尽管我的应用程序现在可以按我希望的方式运行,但是我仍然希望对以前的问题有所了解,以期获得更好的理解。 If anyone can help any further, I would be grateful. 如果有人能进一步帮助我,我将不胜感激。

Thanks alot. 非常感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM