[英]resource cannot be found , wcf
這是我的 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瀏覽器顯示錯誤:
無法找到該資源。
這個配置解決了我的問題:
<?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>
我們應該在 Restful 服務端點上應用傳輸安全模式。 然后將證書綁定到特定端口。 這一般由 IIS 站點綁定模塊完成。
我們也可以使用Netsh HTTP命令。
https://docs.microsoft.com/en-us/windows/win32/http/add-sslcert
此外,請將您的回復標記為解決方案,以幫助遇到類似問題的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.