2011-07-01 9 views
14

सर्वर config:कम से कम एक सुरक्षा टोकन सत्यापित नहीं किया जा सकता है

<?xml version="1.0"?> 
<configuration> 
<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="ServiceCredentialsBehavior"> 
       <serviceCredentials> 
        <serviceCertificate findValue="cn=cool" storeName="TrustedPeople" storeLocation="CurrentUser" /> 
       </serviceCredentials> 
       <serviceMetadata httpGetEnabled="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="ServiceCredentialsBehavior" name="Service"> 
      <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService"/> 
     </service> 
    </services> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="MessageAndUserName"> 
       <security mode="Message"> 
        <message clientCredentialType="UserName"/> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client/> 
</system.serviceModel> 
<system.web> 
    <compilation debug="true"/> 
</system.web> 

मेरे क्लाइंट config:

<?xml version="1.0" encoding="utf-8"?> 
    <configuration> 
<system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="LocalCertValidation"> 
       <clientCredentials> 
        <serviceCertificate> 
         <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" /> 
        </serviceCertificate> 
       </clientCredentials> 
      </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_IService" > 
       <security mode="Message"> 
        <message clientCredentialType="UserName" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:48097/WCFServer/Service.svc" 
        binding="wsHttpBinding" 
        bindingConfiguration="WSHttpBinding_IService" 
        contract="ServiceReference1.IService" 
        name="WSHttpBinding_IService" behaviorConfiguration="LocalCertValidation"> 
      <identity> 
       <dns value ="cool" /> 
      </identity> 
     </endpoint> 
    </client> 
</system.serviceModel> 

सेवा:

public string TestAccess() 
{ 
    return OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name; 
} 

ग्राहक:

 ServiceClient client = new ServiceClient(); 
     client.ClientCredentials.UserName.UserName = "Admin"; 
     client.ClientCredentials.UserName.Password = "123"; 
     Console.WriteLine(client.TestAccess()); 
     Console.ReadLine(); 

त्रुटि:
एक असुरक्षित या गलत तरीके से सुरक्षित गलती अन्य पार्टी से प्राप्त किया गया था। गलती कोड और विवरण के लिए आंतरिक FaultException देखें।
आंतरिक अपवाद:
संदेश में कम से कम एक सुरक्षा टोकन को सत्यापित नहीं किया जा सका।

मैं इस अपवाद को कैसे हल करूं?

उत्तर

21

मुझे लगता है कि समस्या आपका उपयोगकर्ता नाम और पासवर्ड है। डिफ़ॉल्ट कॉन्फ़िगरेशन के साथ उपयोगकर्ता नाम और पासवर्ड विंडोज खाते के रूप में मान्य है। यदि आप अन्य सत्यापन चाहते हैं तो आपको या तो membership provider या custom user name password validator का उपयोग करना होगा।

+1

धन्यवाद बहुत आदमी, मैंने आपकी मदद के बिना 1 सप्ताह में इस साधारण उदाहरण पर काम किया, मैं और अधिक काम करूंगा। अब यह काम कर रहा है। – croisharp

+0

चीयर्स, यह एक बहुत अच्छा जवाब था .. एक आकर्षण की तरह काम करता है! – Sandepku

3

चूंकि त्रुटि संदेश बल्कि अस्पष्ट है, सोचा कि मैं इसे एक और संभावित समाधान के रूप में बाहर रखूंगा।

एएसपी.नेट एमवीसी साइट के माध्यम से उपयोगकर्ता को प्रमाणीकृत करने के लिए मेरा पर्यावरण एकल साइन ऑन (या यदि आप चाहें तो एसटीएस) का उपयोग करता है। एमवीसी साइट बदले में मेरे सेवा एंडपॉइंट पर बेयरर टोकन पास करके एक सेवा कॉल करता है जिसे उसने एसटीएस सर्वर से पहले बूटस्ट्रैप टोकन के साथ अनुरोध किया था। जब मुझे एमवीसी साइट से सर्विस कॉल किया गया तो मुझे मिली त्रुटि थी।

मेरे मामले में, यह मेरी सेवा की कॉन्फ़िगरेशन के कारण नीचे बताए गए अनुसार है। विशेष रूप से दर्शक यूरिस नोड, यह बिल्कुल सेवा अंतराल से मेल खाना चाहिए:

<system.identityModel> 
    <identityConfiguration> 
     <audienceUris> 
      <add value="https://localhost/IdpExample.YService/YService.svc" /> 
     </audienceUris> 
     .... 
    </identityConfiguration> 
</system.identityModel> 

एचटीएच।

संबंधित मुद्दे