消息包含无效或过期的安全上下文令牌,或者因为绑定之间存在不匹配

时间:2013-06-25 11:27:16

标签: c# .net wcf wshttpbinding

我有一个使用web.config的wcf服务的示例Web应用程序

<system.serviceModel>
  <bindings>
  <wsHttpBinding>
    <binding name="TheBindingConfig">
      <security mode="None" >
         <transport clientCredentialType="None" />
    <message establishSecurityContext="false" />    
    </security>
    </binding>
  </wsHttpBinding>
</bindings>   
    <client>
      <endpoint address="http://localhost/myservice/Service.svc"
        binding="wsHttpBinding" bindingConfiguration="TheBindingConfig"
        contract="myservice.IService" name="WSHttpBinding_IService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

和wcf服务配置文件如下

<system.serviceModel>
        <services>
            <service name="myservice.Service" behaviorConfiguration="ServiceBehavior">
                <!-- Service Endpoints -->
                <endpoint address="" binding="wsHttpBinding" contract="myservice.IService">
                    <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true" />
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>

注意服务是使用命名空间“ myservice

创建的

我是错误回复

The message could not be processed. This is most likely because the action 'http://tempuri.org/IService/GetUserDetails' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.

并将跟踪堆栈为

[FaultException: The message could not be processed. This is most likely because the action 'http://tempuri.org/IService/GetUserDetails' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9439503
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
   sampleuserservice.IService.GetUserDetails(String Username) +0
   sampleuserservice._Default.BindUserDetails() +57
   sampleuserservice._Default.Page_Load(Object sender, EventArgs e) +90
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

注意:服务按预期正常运行

我猜上面的webconfig文件之间存在映射问题

等待您的宝贵回应和新闻

1 个答案:

答案 0 :(得分:0)

如果服务可以由任何类型的客户端(.net,soapui)使用,则发布工作肥皂请求(标题+正文)和非工作肥皂请求。您可以使用fiddler或wcf日志来获取消息。如果该服务根本没有工作,那么我的猜测是因为客户端配置为根本不使用安全性(安全模式=“无”)并且服务器没有绑定配置,因此使用默认值并且默认对它有一定的安全性。