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>
Czy użytkownikowi "Jeder" Przeczytałem prawa do certyfikaty klucz prywatny? – Huusom
Niestety, "Jeder" == "Wszyscy" – Harald
Tutaj tylko hostuje usługę. Potrzebujesz również klienta, aby zadzwonić do metod obsługi. – Kryptos