2013-08-23 30 views
5

bir test istemciden WCF servisine erişimini, ben şu istisna alıyorum:WCF servis sunucusu-istemci zaman farkı nasıl bağımsız yapılır?

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 --- 

internette bu sorunun temel nedenini arama yaptı. Bunun çoğunlukla istemci-sunucu zaman farkından kaynaklandığını gördüm. Ancak, doğru çözümü bulamadım.

<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> 

ve İstemci Tarafı Yapılandırma:

<?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> 

Herkes bu soruna çözüm bulmak bana yardım edin ardından benim sunucu tarafı yapılandırma olduğunu.

GÜNCELLEME: Ben istisna takip zaman, iç istisna bu 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'.

Benim sunucuyu gösteriyor UTC biçimi kullanır ve müvekkilim herhangi bir ülkeden indirilebilir bir genel amaçlı bir uygulamadır.

GÜNCELLEME 2: cevap sonrasında Yapılandırma:

<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- çarpık olduğunu hata yardımcı olabilir. – Neha

+0

@Neha Yukarıdaki bağlantıyı kontrol ettim. Ancak müşterim, herhangi bir ülkeden indirilebilen genel amaçlı bir uygulama olduğu için farklı saat dilimlerini kullanabilir. Lütfen benim soru güncellememe bir göz atın. –

+1

google diyor ... maxClockSkew değiştirmeye çalışın ... http://forums.asp.net/t/1834072.aspx/1 – Neha

cevap

3

bu hatanın, ortak bir (belki değil aynı etki alanında) variosu nedenlerle sunucu kimlik doğrulaması olmayan istemci ile ilgilidir birden çok nedeni olabilir . Tam nedenlerini belirlemek için turn on wcf trace ve hangi hataların kırmızı renkte olduğunu görün. Aradığınız şey, izleme UI'sinde biraz gizli olan inenr istisnasıdır, ağacın ortasındaki sağ taraftadır.

<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> 

Not çarpıklık sadece özel bir bağlayıcı üzerinde tanımlanabilir: Burada

bir saat çarpık nasıl ayarlanacağını olduğunu. WSHttpBinding kullandığınızdan, WCF binding converter aracılığıyla çevrimiçi olarak kolayca yapılabilen özel bir ciltlemeye dönüştürmeniz gerekir.

+0

İç istisnadan elde ettiğim şey bu: ' Güvenlik zaman damgası eskidir, çünkü sona erme süresi ('2013-08-21T11: 17: 39.482Z') geçmişte. Şu anki zaman '2013-08-21T12: 31: 31.897Z' ve izin verilen saat eğimi '00: 05: 00 '.

+0

Her iki makinedeki saatlerin doğru olduğunu kontrol edin (5 dak. Fark tamamdır) , gün ışığından yararlanma saati ayarı dahil. sadece sınama amacıyla bunları saat, gün ışığı ve saat dilimi açısından senkronize edin ve yardımcı olup olmadığını görün. –

+0

İstemciyi değiştirdim ve işe yaradı. Müvekkilim indirilebilir bir uygulamadır ve benim sunucu UTC kullanır benim sorum güncellemede söylediğimiz gibi (Sunucu Zamanı değiştiremeyiz, onun müşterileri diğer türleri tarafından kullanılmıştır). Yani müşterim herhangi bir saat dilimini kullanabilir. Bu hata, sunucudan daha fazla saat dilimi farkına sahip olan istemcilerde yeniden görünecektir. Yani buna genel bir çözüm var mı? Böylece müşteri başvurum dünyanın herhangi bir yerinde kullanılabilir mi? (Tabii her ikisi de NY 7 yüzden LA 10 olmalıdır örn bile, aynı UTC saat atıfta emin olun) farklı zaman dilimleri için değişim ve bakın - –

0

Aynı sorunu yaşadım ve tüm önerileri takip ettim. Ama benim hatam sadece sunucu konfigürasyonunu değiştirdiğimde, müşteri konfigürasyonunu da değiştirmem gerekti.

Bu benim 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> 

olmadan yapılandırma Ve saati ile güncellenen

<?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> 
İlgili konular