1

I tried to consome a WCF service configured with CustomBinding and SSL/TLC Certificate but i Get everytime a System.ServiceModel.EndpointNotFoundException «There was no listening endpoint on https: //localhost/Helloword/HelloWord.svc that can accept the message.»

Here is my Service 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>

And There is my Client 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>

The 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();
            }
        }
    }
}

I get Error in : var result = client.HelloWord(input);

In the Browser, the Service looks fine

enter image description here

Thanks for your reply

kaisfarza
  • 73
  • 1
  • 7
  • Maybe try using system.diagnostic trace logs to see if you get a better idea on what the error is: https://stackoverflow.com/a/4271597/2016162 – Popo Jan 10 '19 at 01:22
  • Using Diagnostic i get this error : Failed to lookup a channel to receive an incoming message. Either the endpoint or the SOAP action was not found – kaisfarza Jan 10 '19 at 13:29
  • Do you have the correct contract value in your client endpoint section? – Popo Jan 10 '19 at 21:30
  • Yes it is correct, when i change Binding to BasicHttpBehavior it works, – kaisfarza Jan 11 '19 at 12:42
  • I noticed that you assigned the absolute address and base address to the service endpoint. There is one thing should be noted is that the base address is provided by IIS when hosted in IIS. It is unnecessary to specify the absolute uri. https://social.msdn.microsoft.com/Forums/vstudio/en-US/d42fc165-052d-476a-9580-1240b3d0293d/specify-endpoint-in-wcf-webconfig?forum=wcf – Abraham Qian Jan 15 '19 at 08:13

0 Answers0