WCF:调用方未由服务器进行身份验证

错误描述:

1. WCF:调用方未由服务器进行身份验证

2. 无法处理消息。这很可能是因为操作“http://tempuri.org/ISCCLSvc/GetCarriersByWareHouse”不正确,或因为消息包含无效或过期的安全上下文令牌,或因为绑定之间出现不匹配。如果由于未处于活动状态导致服务中止了该通道,则安全上下文令牌无效。若要防止服务永久中止闲置会话,请增加服务终结点绑定上的接收超时。

3.或并发测试时,高并发出现问题2,实际案例:公司测试部门结果是并发到50就会出现问题2错误,并且平均响应时间也会很慢

解决后结果:

接口测试并发100无问题,并且平均响应时间减小5倍时间!

解决方法:

主要修改红色文本区域

<system.serviceModel>
   <bindings>
      <wsHttpBinding>
        <binding name="NoneSecurity"
          maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/>
          <security mode="None"/>
        </binding>
      </wsHttpBinding>
    </bindings>

    <services>
    <service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
     <!-- Service Endpoints -->
     <endpoint address="" binding="wsHttpBinding" bindingConfiguration="NoneSecurity" contract="WcfService2.IService1">
      <!-- 
              部署时,应删除或替换下列标识元素,以反映
              在其下运行部署服务的标识。删除之后,WCF 将
              自动推导相应标识。
          -->
      <identity>
       <dns value="localhost"/>
      </identity>
     </endpoint>
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
   </services>
   <behaviors>
    <serviceBehaviors>
     <behavior name="WcfService2.Service1Behavior">
      <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点-->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->
      <serviceDebug includeExceptionDetailInFaults="false"/>
     </behavior>
    </serviceBehaviors>
   </behaviors>
</system.serviceModel>
</configuration>

客户端将security配置改为<security mode="None"/>

详细错误信息:

 
  1. <p></p><p>System.ServiceModel.Security.MessageSecurityException was unhandled  
  2.   Message=An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.  
  3.   Source=mscorlib  
  4.   StackTrace:  
  5.     Server stack trace:   
  6.        at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.ProcessReply(Message reply, TimeSpan timeout, SecurityProtocolCorrelationState correlationState)  
  7.        at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)  
  8.        at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)  
  9.        at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)  
  10.        at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)  
  11.        at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)  
  12.     Exception rethrown at [0]:   
  13.        at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)  
  14.        at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)  
  15.        at ApiStressTest.SCCL.ISCCLSvc.GetCarriersByWareHouse(TransModel tm)  
  16.        at ApiStressTest.SCCL.SCCLSvcClient.GetCarriersByWareHouse(TransModel tm) in D:SCCLApiTest.newApiStressTestService ReferencesSCCLReference.cs:line 198  
  17.        at ApiStressTest.ServiceWrapper.ServiceAPIWrapperMethod(Object stateInfo) in D:SCCLApiTest.newApiStressTestSCCLProgram.cs:line 416  
  18.        at System.Threading.ThreadHelper.ThreadStart_Context(Object state)  
  19.        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)  
  20.        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
  21.        at System.Threading.ThreadHelper.ThreadStart(Object obj)  
  22.   InnerException: System.ServiceModel.FaultException  
  23.        Message=无法处理消息。这很可能是因为操作“http://tempuri.org/ISCSvc/GetHouse”不正确,或因为消息包含无效或过期的安全上下文令牌,或因为绑定之间出现不匹配。如果由于未处于活动状态导致服务中止了该通道,则安全上下文令牌无效。若要防止服务永久中止闲置会话,请增加服务终结点绑定上的接收超时。  
  24.        InnerException:   
原文地址:https://www.cnblogs.com/dogxuefeng/p/5691174.html