2013-08-23 33 views
5

Trong khi truy cập vào dịch vụ WCF từ một khách hàng kiểm tra, tôi nhận được ngoại lệ sau đây:Làm thế nào để làm cho sự khác biệt thời gian máy chủ dịch vụ WCF khách hàng độc lập?

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

Tôi tìm kiếm trên internet nguyên nhân gốc rễ của vấn đề này. Tôi thấy rằng điều này chủ yếu là do sự khác biệt thời gian máy chủ khách hàng. Nhưng tôi không thể tìm ra giải pháp đúng cho nó. Sau đây là cấu hình phía máy chủ của tôi:

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

và Client Side Cấu hình:

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

Bất cứ ai hãy giúp tôi tìm ra giải pháp cho vấn đề này.

UPDATE: Khi tôi bắt nguồn từ những ngoại lệ, ngoại trừ bên trong được thể hiện 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'.

My server này sử dụng định dạng UTC và khách hàng của tôi là một ứng dụng mục đích chung mà có thể được tải về từ bất cứ nước nào.

UPDATE 2: Config sau câu trả lời:

<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ỗi có thể hữu ích. – Neha

+0

@Neha Tôi đã kiểm tra liên kết ở trên. Nhưng khách hàng của tôi có thể sử dụng các múi giờ khác nhau vì nó là một ứng dụng có mục đích chung có thể được tải xuống từ bất kỳ quốc gia nào. Vui lòng xem xét cập nhật câu hỏi của tôi. –

+1

Như google nói ... Hãy thử thay đổi maxClockSkew ... http://forums.asp.net/t/1834072.aspx/1 – Neha

Trả lời

3

Có thể có nhiều lý do cho lỗi này, là phổ biến có liên quan đến máy chủ không chứng thực khách hàng vì những lý do variosu (có thể không phải trên cùng một tên miền) . Để xác định lý do chính xác turn on wcf trace và xem lỗi nào hiển thị bằng màu đỏ. Những gì bạn đang tìm kiếm là ngoại lệ inenr mà là một chút ẩn trong dấu vết giao diện người dùng, nó là ở phía bên phải ở giữa xuống cây.

Dưới đây là làm thế nào để thiết lập một nghiêng đồng hồ:

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

Note lệch chỉ có thể được xác định trên một tùy chỉnh ràng buộc. Vì bạn sử dụng WSHttpBinding, bạn cần phải chuyển đổi nó thành một ràng buộc tùy chỉnh có thể dễ dàng được thực hiện trực tuyến thông qua WCF binding converter.

+0

Đây là những gì tôi nhận được từ ngoại lệ bên trong: ' Dấu thời gian bảo mật là cũ vì thời gian hết hạn của nó ('2013-08-21T11: 17: 39.482Z') là trong quá khứ. Thời gian hiện tại là '2013-08-21T12: 31: 31.897Z' và cho phép đồng hồ nghiêng là '00: 05: 00 '.

+0

kiểm tra xem đồng hồ ở cả hai máy có chính xác không (tối đa 5 phút là ok) , bao gồm cài đặt thời gian tiết kiệm ánh sáng ban ngày. chỉ với mục đích thử nghiệm đồng bộ hóa chúng theo giờ, ánh sáng ban ngày và múi giờ và xem điều đó có giúp ích gì không. –

+0

Tôi đã thay đổi thời gian khách hàng và nó hoạt động. Nhưng như tôi đã nói trong câu hỏi của tôi cập nhật rằng khách hàng của tôi là một ứng dụng tải về và máy chủ của tôi sử dụng UTC (tôi không thể thay đổi thời gian máy chủ, nó được sử dụng bởi các loại máy khách khác). Vì vậy, khách hàng của tôi có thể sử dụng bất kỳ múi giờ nào. Lỗi này sẽ xuất hiện lại trong các ứng dụng khách có chênh lệch múi giờ nhiều hơn từ máy chủ. Vì vậy, có bất kỳ giải pháp chung cho điều này? Vì vậy, ứng dụng khách hàng của tôi có thể được sử dụng từ bất kỳ phần nào của thế giới? –

0

Tôi gặp vấn đề tương tự và đã làm theo tất cả các đề xuất. Nhưng lỗi của tôi là tôi chỉ thay đổi cấu hình máy chủ, trong khi tôi cũng phải thay đổi cấu hình máy khách.

Đây là cấu hình của tôi mà không 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> 

Và cập nhật với đồng hồ nghiêng

<?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> 
Các vấn đề liên quan