2009-08-18 14 views
7

के साथ डब्ल्यूसीएफ सेवा एंडपॉइंट सुरक्षित करना मैं डब्ल्यूसीएफ सेवा के कुछ अंतराल को सुरक्षित करना चाहता हूं, मुझे नहीं पता कि आप कुछ एंडपॉइंट सुरक्षित कर सकते हैं और कुछ नहीं। नीचे मेरे पास छीन ली गई डब्ल्यूसीएफ सेवा (स्वयं होस्टेड) ​​है। वही डब्ल्यूसीएफ सीए पॉलिसी फाइल भी पेश करता है। अगर मैं इस डब्ल्यूसीएफ सेवा को सुरक्षित करता हूं या सीए पॉलिसी भाग के कुछ अंतराल को मुझे उपयोगकर्ता नाम पासवर्ड नहीं पूछना चाहिए। पॉलिसी फाइल हर समय सुलभ होनी चाहिए। क्या यह भी संभव है?कस्टम प्रमाणीकरण

मुझे बहुत डब्लूसीएफ कस्टम ब्लॉग/पोस्टिंग मिलीं। सुरक्षा करने के कई तरीके हैं। मैं चाहता हूं कि मैं उपयोगकर्ता नाम/पासवर्ड के साथ कुछ अंतराल सुरक्षित कर सकूं लेकिन क्रेडेंशियल्स को फिडलर जैसे टूल के साथ दिखाई नहीं देनी चाहिए। डेटा हालांकि यह इस मामले में दिखाई दे सकता है।

मैंने पहले से ही एक कस्टम वैलिडेटर लागू किया है लेकिन app.config फ़ाइल चीजों को परिभाषित करने के लिए भी आयातक है। और मैं उस पर बहुत अच्छा नहीं हूँ।

namespace WindowsFormsApplication11 
{ 
    public partial class Form1 : Form 
    { 
     public ServiceHost _host = null; 

     public Form1() 
     { 
      InitializeComponent(); 
     }  

     private void button1_Click(object sender, EventArgs e) 
     { 
      // Create a ServiceHost for the CalculatorService type and 
      // provide the base address. 
      _host = new ServiceHost(typeof(WmsStatService)); 
      _host.AddServiceEndpoint(typeof(IPolicyProvider), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior()); 

      _host.Open(); 
     } 
    } 

    // Define a service contract. 
    [ServiceContract(Namespace = "http://WindowsFormsApplication11")] 
    public interface IWmsStat 
    { 
     [OperationContract] 
     string getConnectedViewers(string channelName); 
     [OperationContract] 
     string sayHello(string name); 
    } 

    [ServiceContract] 
    public interface IPolicyProvider 
    { 
     [OperationContract, WebGet(UriTemplate = "/ClientAccessPolicy.xml")] 
     Stream ProvidePolicy(); 
    } 
    //[DataContract] 
    public class Ads 
    { 
     // [DataMember] 
     public string AdFileName { get; set; } 
     //[DataMember] 
     public string AdDestenationUrl { get; set; } 
     public string ConnectedUserIP { get; set; } 
    } 
    // 
    public class CustomValidator : UserNamePasswordValidator 
    { 
     public override void Validate(string userName, string password) 
     { 
      if(null == userName || null == password) 
      { 
        throw new ArgumentNullException(); 
      } 
      if(userName == "Oguz" && password == "2009") 
      { 
       return; 
      } 
      FaultCode fc = new FaultCode("ValidationFailed"); 
      FaultReason fr = new FaultReason("Good reason"); 
      throw new FaultException(fr,fc); 
     } 
    } 
    // 

    public class WmsStatService : IWmsStat, IPolicyProvider 
    { 
     public string sayHello(string name) 
     { 
      return "hello there " + name + " nice to meet you!"; 
     } 

     public Stream ProvidePolicy() 
     { 
      WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml"; 
      return new MemoryStream(File.ReadAllBytes("ClientAccessPolicy.xml"), false); 
     } 

     public string getConnectedViewers(string channelname) 
     { 
      // do stuff 
      return null; 
     } 
    } 
} 

app.config। यह कॉन्फ़िगरेशन फ़ाइल काम नहीं करती है। मैं एक एंडपॉइंट के लिए कस्टम प्रमाणीकरण रखना चाहता था। मेरे पास कोई सुराग नहीं है।

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="WindowsFormsApplication11.WmsStatService" behaviorConfiguration="mex"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://192.168.0.199:87" /> 
      </baseAddresses> 
     </host>   
     <endpoint address="http://192.168.0.199:87/Test" binding="basicHttpBinding" bindingConfiguration="" contract="WindowsFormsApplication11.IWmsStat" behaviorConfiguration="MyServiceBehavior" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 

    <!--<bindings> 
     <wsHttpBinding>  
     <binding name="wshttp"> 
      <security mode="Message"> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings>--> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="mex"> 
      <serviceMetadata httpGetEnabled="true" httpGetUrl=""/> 
     </behavior> 
     <behavior name="MyServiceBehavior"> 
      <serviceCredentials> 
      <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WindowsFormsApplication11.CustomValidator, CustomValidator" /> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors>  
    </behaviors> 
    </system.serviceModel> 
</configuration> 

उत्तर

17

मैं एक WCF सेवा के कुछ endpoint सुरक्षित करना चाहते हैं, मुझे नहीं पता है अगर आप कुछ endpoint और कुछ नहीं सुरक्षित कर सकते हैं। -

सुनिश्चित करें कि आप सिर्फ दूसरों पर अन्य दो अलग-अलग बाध्यकारी विन्यास बनाने के लिए, और उन अंतिमबिंदुओं कि सुरक्षित हैं पर किसी एक का उपयोग की जरूरत है:

<bindings> 
    <basicHttpBinding> 
    <binding name="secured"> 
     <security mode="Message"> 
     <message ...... /> 
     </security> 
    </binding> 
    <binding name="unsecured"> 
     <security mode="None" /> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<services> 
    <service name="WindowsFormsApplication11.WmsStatService" behaviorConfiguration="mex"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://192.168.0.199:87" /> 
     </baseAddresses> 
    </host>   

    <endpoint address="/Secured/Test" 
       binding="basicHttpBinding" bindingConfiguration="secured" 
       contract="WindowsFormsApplication11.IWmsStat" 
       behaviorConfiguration="MyServiceBehavior" /> 

    <endpoint address="/Unsecured/Test" 
       binding="basicHttpBinding" bindingConfiguration="unsecured" 
       contract="WindowsFormsApplication11.IWmsStat" 
       behaviorConfiguration="MyServiceBehavior" /> 

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

मार्क

पुनश्च: यकीन नहीं अगर यह आपकी पोस्टिंग के साथ अभी तक कोई समस्या नहीं है - क्या आपने देखा है कि आपके पास दो अलग-अलग व्यवहार कॉन्फ़िगरेशन हैं:

<behaviors> 
    <serviceBehaviors> 
     <behavior name="mex"> 
     <serviceMetadata httpGetEnabled="true" httpGetUrl=""/> 
     </behavior> 
     <behavior name="MyServiceBehavior"> 
     <serviceCredentials> 
      <userNameAuthentication 
       userNamePasswordValidationMode="Custom" 
       customUserNamePasswordValidatorType="WindowsFormsApplication11.CustomValidator, CustomValidator" /> 
     </serviceCredentials> 
     </behavior> 
    </serviceBehaviors>  
</behaviors> 

और आपकी सेवा केवल "मेक्सिको" व्यवहार का संदर्भ दे रही है? इसका मतलब है, आपकी सेवा वास्तव में <serviceMetadata> व्यवहार का उपयोग कर रही है - लेकिन <serviceCredentials> एक!

<behaviors> 
    <serviceBehaviors> 
     <behavior name="Default"> 
     <serviceMetadata httpGetEnabled="true" httpGetUrl=""/> 
     <serviceCredentials> 
      <userNameAuthentication 
       userNamePasswordValidationMode="Custom" 
       customUserNamePasswordValidatorType="WindowsFormsApplication11.CustomValidator, CustomValidator" /> 
     </serviceCredentials> 
     </behavior> 
    </serviceBehaviors>  
</behaviors> 
<services> 
    <service name="...." behaviorConfiguration="Default" 

मार्क

+0

अरे मैं इस अब :( फ़ाइल या विधानसभा 'CustomValidator' या अपनी निर्भरता से एक लोड नहीं कर सका हो रही है प्रणाली निर्दिष्ट फ़ाइल नहीं मिल सकता है – Shift

+0

कि त्रुटि इस config यहाँ से आता है userNamePasswordValidationMode = "कस्टम" customUserNamePasswordValidatorType = "WindowsFormsApplication11.CustomValidator, CustomValidator" /> "CustomValidator" विधानसभा उपलब्ध मैं बदल कि जब आप अपने सेवा ?? –

+0

चलने वाले WindowsFormsAppiication11 करने के लिए। यह एक आत्म WCF की मेजबानी की है विंडोज़ फॉर्म पर सेवा। मैंने इसे बदलने के बाद कहा कि त्रुटि खत्म हो गई है लेकिन एक और मुद्दा :( 'http://192.168.0.199:87/Test' पर चैनलडिस्परचर 'IWmsStat' 'के साथ' IWmsStat "'अपने आईसीएचनल लिस्टनर – Shift

2

यदि आप पूरे संदेश की रक्षा करना चाहते हैं, तो परिवहन सुरक्षा मोड जाने का एक तरीका है। अगर आप केवल अपने हेडर को एन्क्रिप्ट/हस्ताक्षरित करना चाहते हैं, तो संदेश सुरक्षा मोड इसे अनुमति देता है, लेकिन आपको wsHttp बाइंडिंग का उपयोग करना होगा। आप प्रमाण-पत्रों की सुरक्षा के लिए डाइजेस्ट का उपयोग करने पर भी विचार कर सकते हैं।

अपने उदाहरण के रूप में, मुझे लगता है कि आपके टिप्पणी की भाग इस तरह दिखना चाहिए:

<bindings> 
    <basicHttpBinding> 
      <binding name="secure"> 
     <security mode="Transport"> 
     <transport clientCredentialType="Basic" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

आप भी अपने अंतिम बिंदु प्रकटीकरण को अपडेट करना होगा:

<endpoint 
    address="https://192.168.0.199:87/Test" 
    binding="basicHttpBinding" bindingConfiguration="secure" 
    contract="WindowsFormsApplication11.IWmsStat" /> 

आप अनुमति नहीं दी जाएगी परिवहन सुरक्षा मोड के साथ सादे HTTP का उपयोग करने के लिए।

+0

कि विन्यास मैं निम्न त्रुटि हो रही है के साथ:

आप एक में इन विलय करने के लिए और फिर बस संदर्भ की जरूरत है। 'MyServiceBehavior' नामक कोई एंडपॉइंट व्यवहार नहीं है – Shift

+0

मैं https का उपयोग नहीं करना चाहता हूं इसलिए मैंने संदेश सुरक्षा मोड – Shift

+0

स्थानांतरित किया है कॉन्फ़िगरेशन = "कैलकुलेटर सेवा सेवाकर्ता"> सेवा टैग पर –

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