The request for security token could not be satisfied because authentication failed.
[SecurityNegotiationException: 调用方未由服务进行身份验证。]
解决方法:
在服务端配置文件添加<binding>配置验证<Security=“none”>,客户端配置验证<Security=“none”>
Code
<!--dhl-->
<system.serviceModel>
<services>
<service behaviorConfiguration="PingCoCMS.Service.Implementation.GuestBookServiceBehavior"
name="PingCoCMS.Service.Implementation.GuestBookService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="NoneSecurity" contract="PingCoCMS.Service.Interfaces.ServiceContracts.IGuestBookService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="PingCoCMS.Service.Implementation.CMSServiceBehavior"
name="PingCoCMS.Service.Implementation.CMSService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="NoneSecurity" contract="PingCoCMS.Service.Interfaces.ServiceContracts.ICMSService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="NoneSecurity"
maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
<readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/>
<security mode="None"/>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="PingCoCMS.Service.Implementation.GuestBookServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="PingCoCMS.Service.Implementation.CMSServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
资料:
一直在一台电脑上同时搞WCF的服务和客户端,今天在另外一台电脑上调用,发现了一个新的问题"调用方未由服务进行身份验证",
在网上查了大量的资料,也没有发现有人说明白其中的原因,只是发现了一篇解决的办法,但是个人感觉不是最佳的方案,所以还在探索中.
发现的解决的办法中提到,在服务端和客户端分别将安全验证设置成"none"就可以了,自己试了几遍也没成功.但是从理论上是行的通的.
另外发现了一个解决办法,不知道有没有其它的见解
将 WCF 服务器和客户端分别部署到不同机器上,可能会触发如下异常。
未处理 System.ServiceModel.Security.SecurityNegotiationException
Message="服务器已拒绝客户端凭据。"
Source="mscorlib"
解决方法,就是调整服务器端 Binding 的安全方式,比如设为 "None"。
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
ServiceHost host = new ServiceHost(typeof(MyService));
host.AddServiceEndpoint(typeof(IService), binding, "net.tcp://192.168.0.112:8081");
ServiceMetadataBehavior metadata = new ServiceMetadataBehavior();
metadata.HttpGetUrl = new Uri("http://192.168.0.112:8080");
metadata.HttpGetEnabled = true;
host.Description.Behaviors.Add(metadata);
host.Open();
或者在配置文件中设置。