WCF安全性实现错误

时间:2012-01-11 14:01:07

标签: wcf security

这是我得到的错误:

无法处理邮件。这很可能是因为行动' 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>

任何人都可以弄清楚我的配置文件有什么问题吗?

2 个答案:

答案 0 :(得分:0)

在你的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并检查日志以确定请求失败的原因。

希望有所帮助。

答案 1 :(得分:0)

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