2015-05-19 14 views
8

Próbuję uzyskać minimalny przykład WCF/https działa, ale nie mogę uzyskać dostępu do usługi (zadziwiająco kod działa bez błędów).Minimalny przykład WCF przy użyciu HTTPS

  • Utworzono certyfikat główny:

    MakeCert -n "CN = test" -r -sv Test.pvk TestCert.cer

  • I dodaje się do Certyfikaty systemu Windows.
  • Stworzyłem certyfikat serwera:

    MakeCert -SK TestCom -A Test.pvk -n "CN = TestCom" -ic TestCert.cer -SR LocalMachine -p mój -sky wymiana -pe

  • mam zarezerwowany port url SSL:

    netsh http dodać urlacl URL = https://+:15001/ user = Wszyscy

  • mam ustawić skrótu certyfikatu do portu:

    netsh http dodać sslcert ipport = 0.0.0.0: 15001 CertHash = XXX appid = {76d71921-B40D-4bc8-8fcc-4315b595878e}

  • dodałem TestCom do etc/hosts

teraz stworzyliśmy prosty C# projekt:

namespace ConsoleApplication7 
{ 
    [ServiceContract] 
    public interface ISimpleService 
    { 
     [OperationContract] 
     string SimpleMethod(string msg); 
    } 

    class SimpleService : ISimpleService 
    { 
     public string SimpleMethod(string msg) 
     { 
      return "Hello " + msg; 
     } 
    } 

    class Program 
    { 
     static void Main(string[] args) 
     { 
      ServiceHost host = new ServiceHost(typeof(SimpleService)); 
      try 
      { 
       host.Open(); 
       Console.ReadLine(); 
       host.Close(); 
      } 
      catch (CommunicationException commProblem) 
      { 
       Console.WriteLine("There was a communication problem. " + commProblem.Message); 
       Console.Read(); 
      } 
     } 
    } 
} 

z następującym app.config:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <system.web> 
     <compilation debug="true"/> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehaviors_HTTPSServiceHost" > 
      <serviceMetadata httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="BasicHttpBinding_HTTPSServiceHost"> 
      <security mode="Transport"> 
      <transport clientCredentialType="None" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 

    <services> 
     <service name="ConsoleApplication7.SimpleService" behaviorConfiguration="ServiceBehaviors_HTTPSServiceHost"> 
     <endpoint address="" binding="wsHttpBinding" bindingConfiguration="BasicHttpBinding_HTTPSServiceHost" 
        contract="ConsoleApplication7.ISimpleService"> 
      <identity> 
      <dns value="TestCom"/> 
      </identity> 
     </endpoint> 
     <endpoint name="mex" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="https://TestCom:51001/SimpleService"/> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 

</configuration> 
+0

Czy użytkownikowi "Jeder" Przeczytałem prawa do certyfikaty klucz prywatny? – Huusom

+0

Niestety, "Jeder" == "Wszyscy" – Harald

+0

Tutaj tylko hostuje usługę. Potrzebujesz również klienta, aby zadzwonić do metod obsługi. – Kryptos

Odpowiedz

0

Chyba trzeba dołączyć policyVersion aby go uruchomić jak poniżej

<serviceMetadata httpGetEnabled="True" policyVersion="Policy12"></serviceMetadata> 
+0

Jeśli zmień na aplikacja natychmiast ulegnie awarii, jeśli zmienię ją w ten sposób: problem nadal istnieje i nic się nie zmienia. – Harald

Powiązane problemy