Как я могу решить «Не удалось найти канал для получения входящего сообщения. Либо конечная точка, либо действие SOAP не найдено »С CustomBinding - PullRequest
0 голосов
/ 10 января 2019

Я пытался использовать службу WCF, настроенную с CustomBinding и сертификатом SSL / TLC, но каждый раз получал System.ServiceModel.EndpointNotFoundException «Не было конечной точки прослушивания на https: // localhost / Helloword / HelloWord.svc, который может принять сообщение. »

Вот мой сервис Web.config:

    <?xml version="1.0" encoding="utf-8"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyCustomBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="LocalMachine" />
            </clientCertificate>
            <serviceCertificate findValue="ServerCert" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>
          </serviceCredentials>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="MyCustomBinding">
          <textMessageEncoding />
          <security authenticationMode="CertificateOverTransport" requireSecurityContextCancellation="true"/>
          <httpsTransport authenticationScheme="IntegratedWindowsAuthentication" />
        </binding>
      </customBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service behaviorConfiguration="MyCustomBehavior" name="CustomBindingWifService.HelloWord">
        <host>
          <baseAddresses>
            <add baseAddress ="HelloWord.svc" />
          </baseAddresses>
        </host>
        <endpoint address="https://localhost/Helloword/HelloWord.svc" binding="customBinding"
            bindingConfiguration="MyCustomBinding" contract="CustomBindingWifService.IHelloWord">
          <identity>
            <certificateReference x509FindType="FindBySubjectName" findValue="ServerCert" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

И есть мой клиент App.config

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="MyCustomBinding">
          <textMessageEncoding />
          <security authenticationMode="CertificateOverTransport" requireSecurityContextCancellation="true"/>
          <httpsTransport />
        </binding>
      </customBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="MyCustomBehavior">
          <clientCredentials>
            <clientCertificate
            findValue="ClientCert"
            storeLocation="LocalMachine"
            storeName="My"
            x509FindType="FindBySubjectName" />
            <serviceCertificate>
              <authentication
              certificateValidationMode="PeerTrust"/>
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <client>
      <endpoint address="https://localhost/Helloword/HelloWord.svc"
        binding="customBinding" bindingConfiguration="MyCustomBinding"
        contract="ServiceHelloWord.IHelloWord" name="HelloWordEndPoint" 
        behaviorConfiguration="MyCustomBehavior" />
    </client>
  </system.serviceModel>
</configuration>

Program.cs:

namespace CustomBindingWifServiceClient
{
    public class Program
    {
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => true;

            var channel = new ChannelFactory<ServiceHelloWord.IHelloWord>("HelloWordEndPoint");

            var client = channel.CreateChannel();

            var input = "Client Console";

            while (input != null && input.ToLower() != "exit")
            {
                var result = client.HelloWord(input);
                Console.WriteLine(result);
                input = Console.ReadLine();
            }
        }
    }
}

Я получаю сообщение об ошибке: var result = client.HelloWord (input);

В браузере служба выглядит нормально

enter image description here

Спасибо за ваш ответ

...