ресурс не найден, wcf - PullRequest
       5

ресурс не найден, wcf

1 голос
/ 10 октября 2019

это моя конфигурация службы 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 браузер показывает мне ошибку:

Ресурс не найден.

Ответы [ 2 ]

2 голосов
/ 10 октября 2019

эта конфигурация решила мою проблему:

    <?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>
0 голосов
/ 10 октября 2019

Мы должны применить режим безопасности транспорта на конечной точке сервиса Restful. Затем привяжите сертификат к определенному порту. Обычно это выполняется модулем привязки сайта IIS. enter image description here
И мы также можем использовать команду Netsh HTTP .
https://docs.microsoft.com/en-us/windows/win32/http/add-sslcert
Кроме того, пометьте свой ответ как решение, чтобы помочь тому, ктостолкнулся с аналогичной проблемой.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...