2013-08-05 5 views
7

के साथ HTTP के साथ काम नहीं करती है ठीक है इसलिए मैं एक कंसोल एप्लिकेशन के भीतर एक डब्ल्यूसीएफ सेवा होस्ट कर रहा हूं।स्वयं-होस्टेड डब्ल्यूसीएफ सेवा एचटीटीपीएस

सभी बाइंडिंग प्रोग्रामेटिक रूप से बनाई गई हैं, इसलिए कोई कॉन्फ़िगरेशन सेटिंग्स नहीं है।

मैं जब तक एक काम सेवा है के रूप में मैं HttpTransportBindingElement तथापि का उपयोग जैसे ही मैंने HttpsTransportBindingElement तो कुछ भी नहीं काम करता है का उपयोग करें, सेवा ब्राउज़र के भीतर प्रदर्शित नहीं करता है और क्लाइंट अनुप्रयोग एक 405 (Method Not Allowed) CommunicationException

मैं एक स्थापित करने की कोशिश की है देता है SecurityBindingElement मेरे CustomBinding पर मुझे यकीन नहीं है कि मुझे किस विकल्प का उपयोग करना चाहिए।

SecurityBindingElement.CreateCertificateOverTransportBindingElement()

SecurityBindingElement.CreateAnonymousForCertificateBindingElement()

आदि

मेजबान के निर्माण के लिए कोड है

नीचे
baseAddress = new Uri(string.Format("{0}://{1}", strConnectionType, ConfigurationManager.AppSettings["baseAddress"])); 

      ServiceHost host = new ServiceHost(typeof(IMyService), baseAddress); 

      host.AddServiceEndpoint(typeof(MyService), binding, String.Empty); 

      ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); 
      smb.HttpsGetEnabled = certificate != null; 
      smb.HttpGetEnabled = certificate == null; 

      host.Description.Behaviors.Add(smb); 

      ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>(); 

      if (sdb == null) 
      { 
       host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); 
      } 
      else 
      { 
       if (!sdb.IncludeExceptionDetailInFaults) 
       { 
        sdb.IncludeExceptionDetailInFaults = true; 
       } 
      } 


      if (certificate != null) 
      { 
       host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, certificate.Thumbprint); 
      } 
+1

'बाध्यकारी 'क्या है? डब्ल्यूसीएफ सेवाओं की प्रोग्रामेटिक कॉन्फ़िगरेशन भी कठिन है, कॉन्फ़िगरेशन फ़ाइल का उपयोग क्यों नहीं करें? –

+0

@ ta.speot.is क्या आप अपने प्रश्न पर और विस्तार कर सकते हैं? –

+1

@ shankar-damodaran संपादन के लिए धन्यवाद :) –

उत्तर

6

मैं इस ब्लॉग http://blogs.msdn.com/b/james_osbornes_blog/archive/2010/12/10/selfhosting-a-wcf-service-over-https.aspx जो प्रकाश डाला पीछा इसी क्रम में HTTPS के लिए करने के लिए आपके द्वारा उपयोग किए जा रहे प्रमाणपत्र में बंदरगाह को बांधने की आवश्यकता है।

Process bindPortToCertificate = new Process(); bindPortToCertificate.StartInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "netsh.exe");

bindPortToCertificate.StartInfo.Arguments = string.Format("http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={{{2}}}", port, certificate.Thumbprint, Guid.NewGuid());

bindPortToCertificate.Start();

bindPortToCertificate.WaitForExit();

एक बार यह किया गया था कि यह सब काम किया।

मुझसे संपर्क करें यदि किसी को प्रोग्रामिंग सेट के साथ एक स्वयं-होस्टेड डब्ल्यूसीएफ सर्वर की स्थापना और कॉन्फ़िगर करने का मेरा उदाहरण कोड चाहिए। :)

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