我正在尝试使用最小的WCF / https示例,但我无法访问该服务(令人惊讶的是代码运行时没有错误)。
我创建了一个根证书:
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网址保留了一个端口:
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}
我已将TestCom添加到etc / hosts文件
现在我创建了一个简单的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>
答案 0 :(得分:1)
我无法对此帐户发表评论,因此,如果这不是答案,请在下面打开一个对话框,可以缩小范围。将您的设置与我写的here进行交叉引用,您可能会发现设置中我没有的内容。
我最初看到的只是
我已将其添加到Windows根证书中。
A specified logon session does not exist. It may already have been terminated.
如果这是错误,只需检查您将证书导入到正确的位置即可。
导入现有证书
我遇到了wsHttpBinding可能遇到的所有问题,并拥有个人Wiki,如果有任何日志,我可以为您提供更好的帮助,它现在在哪里崩溃?
答案 1 :(得分:0)
猜猜您需要包含policyVersion以使其像下面一样运行
<serviceMetadata httpGetEnabled="True" policyVersion="Policy12"></serviceMetadata>