WCF 服务安全协商异常
题
我正在使用 WCF 在我的服务器上运行一个简单的服务;该服务托管在 WebDev.WebServer.exe(本地)中。
当我调用本地服务时,出现以下异常:
未处理的异常:System.ServiceModel.Security.SecurityNegotiationException:无法打开安全通道,因为与远程端点的安全协商失败。这可能是由于用于创建通道的 EndpointAddress 中缺少 EndpointIdentity 或指定的 EndpointIdentity 不正确。请验证 EndpointAddress 指定或暗示的 EndpointIdentity 是否正确标识远程端点。---> System.ServiceModel.FaultException:带有 Action ' 的消息http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue'由于端点dispatcher的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>
解决方案
的问题是在服务器,我把模式=“消息”和行之有效的。感谢。
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
</security>
其他提示
WCF 非常强大,但可能是配置噩梦。以下是一些潜在的线索:
- 打开 WCF 跟踪日志,重新运行您的方案,然后使用 SvcTraceViewer.exe 检查日志
- 弄清楚消息传递的距离...
- IE。客户端是否形成请求并将其发送到拒绝它的服务器(即在您自己的服务代码被命中之前在较低的 WCF 层中);
- 或者请求是否在此之前停止了......客户端甚至从未发送请求
- http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue 是与 WS-Trust 令牌相关的消息,因此身份验证会发生一些情况
- 该错误意味着配置不匹配,但使用 SvcUtil 应该让它们像你说的那样排列起来
- 客户端绑定的服务器位于“http://localhost:1634/UsuarioContexto.svc"
- 我没有看到服务配置中指定的端口...该服务正在侦听该端口吗?
- 如果您打开浏览器并将其瞄准该 URL,您会得到默认服务页面吗?
不隶属于 StackOverflow