这是我的wcf服务配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings file="db-connection-string.config">
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
<compilation targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="PingServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
<services>
<service name="PingService.PingService" behaviorConfiguration="PingServiceBehavior">
<endpoint address="ws" binding="wsHttpBinding" contract="PingService.IPingService" />
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" contract="PingService.IPingService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
这是服务:
namespace PingService
{
[ServiceContract]
public interface IPingService
{
[WebGet]
[OperationContract]
string Hello();
}
}
当我在浏览器中输入时:https://localhost/PingService/PingService.svc/hello 浏览器显示错误:
找不到资源。
答案 0 :(得分:2)
此配置解决了我的问题:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings file="db-connection-string.config">
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
<compilation targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="SecureWebBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="PingServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SOAPDemoEndpointBehavior">
</behavior>
<behavior name="RESTDemoEndpointBehavior">
<webHttp />
</behavior>
<behavior name="mexBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
<services>
<service name="PingService.PingService" behaviorConfiguration="PingServiceBehavior">
<endpoint address="rest" binding="webHttpBinding" bindingConfiguration="SecureWebBinding" behaviorConfiguration="RESTDemoEndpointBehavior" contract="PingService.IPingService" />
<endpoint address="soap" binding="basicHttpBinding" behaviorConfiguration="SOAPDemoEndpointBehavior" contract="PingService.IPingService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
答案 1 :(得分:0)
我们应该在Restful服务端点上应用传输安全模式。然后将证书绑定到特定端口。这通常由IIS站点绑定模块完成。
我们还可以使用 Netsh HTTP 命令。
https://docs.microsoft.com/en-us/windows/win32/http/add-sslcert
此外,请将您的回复标记为解决方案,以帮助遇到类似问题的人。