【问题标题】:WCF service SecurityNegotiationExceptionWCF 服务 SecurityNegotiationException
【发布时间】:2011-01-09 21:52:52
【问题描述】:

我正在使用 WCF 在我的服务器上运行一个简单的服务;该服务托管在 WebDev.WebServer.exe(本地)中。

当我调用本地服务时,出现以下异常:

未处理的异常:System.ServiceModel.Security.SecurityNegotiationException:无法打开安全通道,因为与远程端点的安全协商失败。这可能是由于用于创建通道的 EndpointAddress 中缺少或错误指定了 EndpointIdentity。 请验证 EndpointAddress 指定或暗示的 EndpointIdentity 是否正确标识了远程端点。 ---> System.ServiceModel.FaultException: 带有 Action 'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue' 的消息不能 由于 EndpointDispatcher 的 ContractFilter 不匹配,在接收方处理。这可能是因为 合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。

这是我来自客户端和服务器的两个 app.config 文件。我使用 svcutil-Tool 从客户端制作了 app.config,所以它应该是正确的:

客户

<client>
    <endpoint address="http://localhost:1634/UsuarioContexto.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IUsuarioContexto"

        contract="CarWin.ServiceContracts.Interfaces.IUsuarioContexto" name="LOCAL_WSHttpBinding_IUsuarioContexto">

        <identity><dns value="localhost" /></identity>

    </endpoint>

</client>

<binding name="WSHttpBinding_IUsuarioContexto" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />

    <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />

    <security mode="Message">

        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />

        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" />

    </security>

</binding>

服务器

<services>
    <service behaviorConfiguration="UsuarioContextoBehavior" name="UserContext.Host.UsuarioContexto">

        <endpoint address="" binding="wsHttpBinding" bindingNamespace="http://CarWin" bindingConfiguration="wsHttpBinding_IUsuarioContexto"

                  contract="CarWin.ServiceContracts.Interfaces.IUsuarioContexto">

            <identity>

                <dns value="localhost" />

            </identity>

        </endpoint>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

    </service>

</services>


<bindings>

    <wsHttpBinding>

        <binding name="wsHttpBinding_IUsuarioContexto" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

            <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" />

            <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />

            <security mode="None">

                <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />

                <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />

            </security>

        </binding>

    </wsHttpBinding>

</bindings>

<behaviors>

    <serviceBehaviors>

        <behavior name="UsuarioContextoBehavior">

            <serviceMetadata httpGetEnabled="true" />

            <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

    </serviceBehaviors>

</behaviors>

【问题讨论】:

    标签: wcf security exception service


    【解决方案1】:

    问题出在服务器上,我设置了 mode="Message" 并且运行良好。谢谢。

    <security mode="None">  
    
    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />  
    
    <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />  
    
    </security> 
    

    【讨论】:

    • 这有帮助,谢谢!我已经被困在这个问题上几个小时了,无法确定为什么当所有其他连接方法完美运行时,SecurityNegotiationException 一直被抛出到我的网络应用程序上。
    • 如果我想要无安全级别怎么办?如何在调用方解决此问题?
    【解决方案2】:

    WCF 非常强大,但可能是配置的噩梦。以下是一些潜在的线索:

    • 打开 WCF 跟踪日志,重新运行您的方案,然后使用 SvcTraceViewer.exe 检查日志
    • 弄清楚消息传递到什么程度...
      • 即客户端是否形成请求并将其发送到拒绝它的服务器(即在您自己的服务代码被命中之前在较低的 WCF 层中);
      • 或者在此之前请求是否停止运行......客户端甚至从未发送过请求
    • http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue 是与 WS-Trust 令牌相关的消息,因此身份验证会发生一些事情
      • 错误暗示存在配置不匹配,但使用 SvcUtil 应该让它们像你说的那样排列起来
    • 客户端绑定的服务器位于“http://localhost:1634/UsuarioContexto.svc
      • 我没有看到服务配置中指定的端口...服务是否正在侦听该端口?
      • 如果您打开浏览器并将其对准该 URL,您会获得默认服务页面吗?

    【讨论】:

    • 问题出在:服务器配置中的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 2020-12-11
    • 1970-01-01
    • 2011-02-08
    • 2013-11-30
    • 2011-02-16
    • 2011-04-22
    相关资源
    最近更新 更多