我试图让一个最小的WCFhttps例子工作,但我无法访问服务(令人惊讶的是,代码运行没有错误)。
我已经创建了一个根证书。
makecert -n "CN=Test" -r -sv Test.pvk TestCert.cer
我已经创建了一个服务器证书。
makecert -sk TestCom -iv Test.pvk -n "CN=TestCom" -ic TestCert.cer -sr LocalMachine -ss my -sky exchange -pe
我已经为SSL url保留了一个端口。
netsh http add urlacl url=https:/+:15001 user=Everyone
我将证书的哈希值设置为端口。
netsh http add sslcert ipport=0.0.0.0:15001 certhash=XXX appid={76d71921-b40d-4bc8-8fcc-4315b595878e}。
我在etchosts文件中加入了TestCom。
现在我已经创建了一个简单的C#项目。
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();
}
}
}
}
有以下的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>
我不能对这个账户进行评论,所以如果这不是答案,请在下面打开对话,并帮助缩小它。将你的设置与我写的内容进行交叉参考 此处 你可能会发现一些我没有发现的东西在你的设置。
我最初能看到的唯一问题是
我已经将它添加到Windows-Root证书中。
A specified logon session does not exist. It may already have been terminated.
如果这是错误,只需检查你导入证书的位置是否正确。
导入现有的证书
wsHttpBinding的所有可能的问题我都打过了,而且有个人的wiki,如果有日志的话,我可以更好的帮助你,目前在哪里崩溃?
估计你需要加入policyVersion,才能使它运行成下面的样子。
<serviceMetadata httpGetEnabled="True" policyVersion="Policy12"></serviceMetadata>