2013-08-23 9 views
5

Durante l'accesso servizio WCF da un client di prova, io sono sempre seguente eccezione:Come rendere indipendente la differenza di orario client-server client-servizio?

System.ServiceModel.Security.MessageSecurityException: An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail. ---> System.ServiceModel.FaultException: An error occurred when verifying security for the message. 
    --- End of inner exception stack trace --- 

ho cercato su internet la causa principale di questo problema. Ho scoperto che questo è causato principalmente a causa della differenza di orario client-server. Ma non sono riuscito a trovare la soluzione giusta. In seguito è la mia configurazione lato server:

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="RequestUserName"> 
      <security mode="Message"> 
       <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" /> 

      </security> 
     </binding> 
     </wsHttpBinding> 

    </bindings> 
    <services> 
     <service name="WCFService.Service1" behaviorConfiguration="WCFService.Service1Behavior"> 
     <!-- Service Endpoints --> 
     <endpoint address="http://subdomain.domain.com/service1.svc" binding="wsHttpBinding" contract="WCFService.IService1" bindingName="RequestUserName"> 


     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 

     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFService.Service1Behavior"> 
      <!-- To avoid disclosing metadata information, set the value below to false before deployment --> 
      <serviceMetadata httpGetEnabled="false" /> 

      <!-- 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> 
    <serviceHostingEnvironment> 
     <baseAddressPrefixFilters> 
     <add prefix="http://subdomain.domain.com/"/> 
     </baseAddressPrefixFilters> 
    </serviceHostingEnvironment> 

e configurazione lato client:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="RequestUserName_IService1" /> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://subdomain.domain.com/service1.svc" binding="wsHttpBinding" 
       bindingConfiguration="RequestUserName_IService1" contract="ServiceReference1.IService1" 
       name="RequestUserName_IService1"> 
       <identity> 
        <userPrincipalName value="DOMAIN\subdomaincom_web" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

Chiunque ti prego, aiutami a trovare la soluzione a questo problema.

UPDATE: Quando ho rintracciato l'eccezione, l'eccezione interna sta mostrando questo The security timestamp is stale because its expiration time ('2013-08-21T11:17:39.482Z') is in the past. Current time is '2013-08-21T12:31:31.897Z' and allowed clock skew is '00:05:00'.

Il server utilizza il formato UTC e il mio cliente è un'applicazione di uso generale che può essere scaricato da qualsiasi paese.

UPDATE 2: Config dopo la risposta:

<system.serviceModel> 
    <bindings> 
     <customBinding> 
     <binding name="Wrabind"> 
      <transactionFlow /> 
      <security authenticationMode="SecureConversation" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"> 
      <localClientSettings maxClockSkew="00:07:00" /> 
      <localServiceSettings maxClockSkew="00:07:00" /> 
      <secureConversationBootstrap messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" /> 
       <localClientSettings maxClockSkew="00:30:00" /> 
       <localServiceSettings maxClockSkew="00:30:00" /> 
      </security> 
      <textMessageEncoding /> 
      <httpTransport /> 
     </binding> 
     </customBinding> 
    </bindings> 
    <!-- change --> 
    <services> 
     <service name="WCFService.Service1" behaviorConfiguration="WCFService.Service1Behavior"> 
     <!-- Service Endpoints --> 
     <endpoint address="http://subdomain.domain.com/service1.svc" binding="customBinding" contract="WCFService.IService1" bindingName="Wrabind"> 
      <!-- 
       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. 
      --> 

     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 

     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFService.Service1Behavior"> 
      <!-- To avoid disclosing metadata information, set the value below to false before deployment --> 
      <serviceMetadata httpGetEnabled="false" /> 
      <!-- change --> 
      <!--<serviceCredentials> 
      <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WCFService.Authentication.DistributorValidator, WrangleCoreService"/> 
      <serviceCertificate findValue="WCFService" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectName"/> 
      </serviceCredentials>--> 
      <!-- change --> 
      <!-- 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> 
    <serviceHostingEnvironment> 
     <baseAddressPrefixFilters> 
     <add prefix="http://subdomain.domain.com/"/> 
     </baseAddressPrefixFilters> 
    </serviceHostingEnvironment> 
    <!--<standardEndpoints> 
     <webHttpEndpoint> 
     <standardEndpoint name="" helpEnabled="true" 
      automaticFormatSelectionEnabled="true"/> 
     </webHttpEndpoint> 
    </standardEndpoints>--> 

    </system.serviceModel> 
+0

http://stackoverflow.com/questions/1484601/wcfan-unsecured-or-incorrectly-fault- l'errore potrebbe aiutare. – Neha

+0

@Neha Ho controllato sopra il collegamento. Ma il mio cliente può utilizzare diversi fusi orari poiché è un'applicazione generica che può essere scaricata da qualsiasi paese. Si prega di dare un'occhiata alla mia domanda di aggiornamento. –

+1

Come dice google ... Prova a cambiare maxClockSkew ... http://forums.asp.net/t/1834072.aspx/1 – Neha

risposta

3

Ci possono essere diverse ragioni per questo errore, quello comune è legato al server client non autenticazione per motivi variosu (forse non sullo stesso dominio) . Per determinare i motivi esatti turn on wcf trace e vedere quali errori mostra in rosso. Quello che stai cercando è l'eccezione inenr che è un po 'nascosta nell'interfaccia utente della traccia, che si trova nella parte destra al centro dell'albero.

Ecco come impostare un orologio skew:

<security authenticationMode="..."> 
      <localClientSettings maxClockSkew="00:07:00" /> 
      <localServiceSettings maxClockSkew="00:07:00" /> 
      <secureConversationBootstrap> 
       <localClientSettings maxClockSkew="00:30:00" /> 
       <localServiceSettings maxClockSkew="00:30:00" /> 
      </secureConversationBootstrap> 
</security> 

Nota skew può essere definito solo su un vincolante personalizzato. Dato che si utilizza WSHttpBinding, è necessario convertirlo in un'associazione personalizzata che può essere facilmente eseguita online tramite WCF binding converter.

+0

Questo è quello che sto ottenendo dall'eccezione interna: ' Il timestamp di sicurezza è scaduto perché la sua scadenza ('2013-08-21T11: 17: 39.482Z') è nel passato. L'ora corrente è '2013-08-21T12: 31: 31.897Z' e l'inclinazione del clock consentita è '00: 05: 00 '.

+0

controllare che gli orologi di entrambe le macchine siano precisi (fino a 5 minuti la differenza è ok) , inclusa l'impostazione dell'ora legale. solo allo scopo di test sincronizzarli in termini di ora, luce diurna e fuso orario e vedere se questo aiuta. –

+0

Ho cambiato l'ora del cliente e ha funzionato. Ma come ho detto nella mia domanda di aggiornamento che il mio client è un'applicazione scaricabile e il mio server utilizza UTC (non posso cambiare il tempo del server, è stato utilizzato da altri tipi di client). Quindi il mio cliente può usare qualsiasi fuso orario. Questo errore riappare in quei client che hanno più differenza di fuso orario dal server. Quindi c'è qualche soluzione generale a questo? In modo che la mia applicazione client possa essere utilizzata da qualsiasi parte del mondo? –

0

Ho avuto lo stesso problema e ho seguito tutte le raccomandazioni. Ma la mia colpa è stata che ho modificato solo la configurazione del server, mentre dovevo cambiare anche la configurazione del client.

Questo è il mio config senza maxClockSkew

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
    <connectionStrings> 
    <!-- --> 
    </connectionStrings> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_IHotLine1" closeTimeout="00:10:00" 
      openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
      maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      <security> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="localhost:6767/blabla.svc" binding="wsHttpBinding" 
     bindingConfiguration="WSHttpBinding_IHotLine1" contract="ServiceReference2.IHotLine" 
     name="WSHttpBinding_IHotLine1"> 
     <identity> 
      <certificate encodedValue="====encodedvalue===" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
</configuration> 

e aggiornato con skew

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
    <system.serviceModel> 
    <bindings> 
     <customBinding> 
     <binding name="WSHttpBinding_IHotLine1"> 
      <transactionFlow/> 
      <security authenticationMode="SecureConversation" 
messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"> 
      <localClientSettings maxClockSkew="01:30:00" /> 
      <localServiceSettings maxClockSkew="01:30:00" /> 
      <secureConversationBootstrap authenticationMode="UserNameForSslNegotiated" 
messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" > 
       <localClientSettings maxClockSkew="01:30:00" /> 
       <localServiceSettings maxClockSkew="01:30:00" /> 
      </secureConversationBootstrap> 
      </security> 
      <textMessageEncoding/> 
      <httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" /> 
     </binding> 
     </customBinding> 
    </bindings> 
    <client> 

     <endpoint address="http://localhost:6767/blabla.svc" binding="customBinding" 
     bindingConfiguration="WSHttpBinding_IHotLine1" contract="ServiceReference2.IHotLine" 
     name="WSHttpBinding_IHotLine1"> 
     <identity> 
      <certificate encodedValue="====encodedvalue===" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
</configuration> 
Problemi correlati