Minimal WCF Example Using HTTPS

I am trying to get a minimal WCF / https example, but I can’t access the service (surprisingly, the code works without errors).

  • I created a root certificate:

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

  • I added it to my Windows-Root certificates.
  • I created a server certificate:

    makecert -sk TestCom -iv Test.pvk -n "CN = TestCom" -ic TestCert.cer -sr LocalMachine -ss my -sky exchange -pe

  • I reserved a port for the SSL URL:

    netsh http add urlacl url = https: // +: 15001 / user = Everyone

  • I set the certificate hash in the port:

    netsh http add sslcert ipport = 0.0.0.0: 15001 certhash = XXX appid = {76d71921-b40d-4bc8-8fcc-4315b595878e}

  • I added TestCom to etc / hosts file

Now I have created a simple C # project:

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(); } } } } 

with the following 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> 
+8
c # wcf
source share
1 answer

Guess that you need to enable policyVersion so that it runs as shown below.

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

All Articles