【问题标题】:WCF security implementation errorWCF 安全实现错误
【发布时间】:2012-02-07 21:13:23
【问题描述】:

这是我得到的错误:

无法处理该消息。这很可能是因为操作“http://tempuri.org/xxxxxx”不正确,或者因为消息包含无效或过期的安全上下文令牌,或者因为绑定之间存在不匹配。如果服务因不活动而中止通道,则安全上下文令牌将无效。为了防止服务过早中止空闲会话,请增加服务端点绑定的接收超时

这是我的 web.config 副本:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
  </system.web>  
   <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsUserNameToken">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None"/>
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="ServiceName" behaviorConfiguration="userNameTokenBehavior">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsUserNameToken" name="userNameTokenService" contract="ContractName"/>
        <endpoint address="mex" binding="wsHttpBinding" bindingConfiguration="wsUserNameToken" name="MexHttpsBindingEndpoint" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="userNameTokenBehavior">
          <serviceMetadata httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <serviceCredentials>
            <serviceCertificate findValue="xxxxxxxxxxxxx" x509FindType="FindByThumbprint" storeLocation="LocalMachine" storeName="My" />
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="xxxxx.xxxxx.UsernameValidator, App_Code"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>  
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
 </configuration>

谁能找出我的配置文件有什么问题?

【问题讨论】:

  • WCF 是客户端和服务器之间的舞蹈。您能否也包括您的客户端配置。
  • 您的服务名称属性和端点合同属性应该是完全限定名称。还可以在您的服务上启用跟踪以了解失败的原因

标签: wcf security


【解决方案1】:

在您的 wsHttpBinding 元素中,您可以添加属性 recieveTimeout 并将其值设置为较大的值并检查。下面是一个示例:

<binding name="wsUserNameToken" 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"
          useDefaultWebProxy="true" allowCookies="false">

还可以尝试在您的服务上启用Tracing 并检查日志以确定请求失败的原因。

希望对您有所帮助。

【讨论】:

  • 这显然不是解决他问题的办法。 WCF 绑定的问题几乎总是不是由超时问题引起的。
【解决方案2】:

检查您的元数据绑定。绑定应该是 mexHttpsBinding 而不是 wsHttpBinding

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-29
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多