简体   繁体   中英

resource cannot be found , wcf

this is my wcf service config:

 <?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>

this is the service:

namespace PingService
{
    [ServiceContract]
    public interface IPingService
    {

        [WebGet]
        [OperationContract]
        string Hello();

    }
}

when i type in browser: https://localhost/PingService/PingService.svc/hello the browser shows me error:

The resource cannot be found.

this configuration solved my problem:

    <?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>

We should apply the Transport security mode on the Restful service endpoint. Then bind a certificate to the specific port. This generally is completed by the IIS site binding module. 在此处输入图像描述
And we could also use Netsh HTTP command.
https://docs.microsoft.com/en-us/windows/win32/http/add-sslcert
Besides, please mark your reply as a solution in order to help whoever ran into a similar problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM