【发布时间】:2017-12-01 01:14:03
【问题描述】:
我设置了一个由 Windows 服务托管的 WCF 应用程序。我让它正常工作,我可以通过转到http://127.0.0.1:1214 导航到它。这是配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="NetworkPrintClient.PrintWebService" behaviorConfiguration="PrintServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:1214/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="NetworkPrintClient.IPrintWebService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PrintServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
现在我想通过https://127.0.0.1:1214 访问它。在阅读了几篇关于这样做的文章后,我最终得到了下面的配置。但是,我不能再浏览到应用程序了。我只是在 Chrome 中收到“无法访问此站点”错误。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="NetworkPrintClient.PrintWebService" behaviorConfiguration="PrintServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="https://127.0.0.1:1214/"/>
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" contract="NetworkPrintClient.IPrintWebService" behaviorConfiguration="HttpBehavior" bindingConfiguration="PrintServiceHttpsBinding"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PrintServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="HttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="PrintServiceHttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add binding="webHttpBinding" scheme="https"/>
</protocolMapping>
</system.serviceModel>
</configuration>
到目前为止,我使用的文章是here。我在底部做了关于制作证书并将其映射到我的 IP 和端口的部分。我还试图让它与“localhost”和我的实际 IP 地址一起使用。谁能看到我做错了什么?
【问题讨论】:
-
您是否尝试过使用 WCF 测试客户端访问您的服务? docs.microsoft.com/en-us/dotnet/framework/wcf/… - 我发现在某些情况下这很有帮助。另外,我建议您从上面的工作版本重新开始,然后在所有其余部分中一块一块地粘上胶水,同时确保每个步骤仍然有效。
标签: c# wcf https windows-services