title: System.ServiceModel.EndpointNotFoundException thrown when consuming wcf service on IIS
body: <p>I created a WCF service to upload file and the WCF service is hosted on windows IIS. I also have a client to consume this WCF service over HTTPS and currently the client and the service are on the same machine. The code is shown below:</p>
  
  <p>IService1.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.ServiceModel.Web;
  using System.Text;
  
  namespace WcfService1
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
      [ServiceContract]
      public interface IService1
      {
  
  
          [OperationContract]
          void UploadFile(RemoteFileInfo request);
  
  
          // TODO: Add your service operations here
      }
  
  
      [MessageContract]
      public class RemoteFileInfo : IDisposable
      {
          [MessageHeader(MustUnderstand = true)]
          public string FilePath;
  
          /*
          [MessageHeader(MustUnderstand = true)]
          public string DestinationDirectory;
          */
  
          [MessageBodyMember(Order = 1)]
          public System.IO.Stream FileByteStream;
  
          public void Dispose()
          {
              if (FileByteStream != null)
              {
                  FileByteStream.Close();
                  FileByteStream = null;
              }
          }
      }
  }
  </code></pre>
  
  <p>Service1.cvs.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  using System.IO;
  using System.ServiceModel.Web;
  using System.Diagnostics;
  
  namespace WcfService1
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
      // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
      public class Service1 : IService1
      {
  
          public void UploadFile(RemoteFileInfo request)
          {
              FileStream targetStream = null;
              Stream sourceStream = request.FileByteStream;
  
              //string destinationDirectory = request.DestinationDirectory;
              Console.WriteLine(request.FilePath);
              string fileName = Path.GetFileName(request.FilePath);
  
              string filePath = Path.Combine("C:\\upload", fileName);
  
              using (targetStream = new FileStream(filePath, FileMode.Create,
                                    FileAccess.Write, FileShare.None))
              {
  
  
                  const int bufferLen = 65000;
                  byte[] buffer = new byte[bufferLen];
                  int count = 0;
                  while ((count = sourceStream.Read(buffer, 0, bufferLen)) &gt; 0)
                  {
  
                      targetStream.Write(buffer, 0, count);
                  }
                  targetStream.Close();
                  sourceStream.Close();
              }
          }
  
  
      }
  }
  </code></pre>
  
  <p>web.config:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  
    &lt;appSettings&gt;
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5"/&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;protocolMapping&gt;
          &lt;add binding="basicHttpsBinding" scheme="https" /&gt;
      &lt;/protocolMapping&gt;    
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
      &lt;!--
          To browse web app root directory during debugging, set the value below to true.
          Set to false before deployment to avoid disclosing web app folder information.
        --&gt;
      &lt;directoryBrowse enabled="true"/&gt;
    &lt;/system.webServer&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Client code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using ClientApp.ServiceReference1;
  
  namespace ClientApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              Service1Client client = new Service1Client();
  
              string FilePath1 = "C:\\Users\\user1\\Desktop\\data.csv";
              System.IO.FileStream stream1 =
              new System.IO.FileStream("C:\\Users\\user1\\Desktop\\data.csv",
              System.IO.FileMode.Open, System.IO.FileAccess.Read);
  
              string dest = "C:\\upload";
              client.UploadFile(FilePath1, stream1);
              client.Close();
  
          }
      }
  }
  </code></pre>
  
  <p>This client code throw exception on the line " <strong>client.UploadFile(FilePath1, stream1);</strong>" :</p>
  
  <pre><code>An unhandled exception of type 'System.ServiceModel.EndpointNotFoundException' occurred in mscorlib.dll
  
  Additional information: There was no endpoint listening at http://localhost:53673/Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
  </code></pre>
  
  <p>However, if I launch browser to access the site, I can access Service1.svc successfully(which means I configure the IIS and post the service to IIS correctly) like the screen shot below:</p>
  
  <p><a href="https://i.stack.imgur.com/ROUG8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ROUG8.png" alt="enter image description here"></a> </p>
  
  <p>I would like to know where the problem is? Thanks in advance!</p>
  
  <p>Edit:</p>
  
  <p>The orignal client's App.config is below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;startup&gt; 
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
      &lt;system.serviceModel&gt;
          &lt;bindings&gt;
              &lt;basicHttpBinding&gt;
                  &lt;binding name="BasicHttpBinding_IService1" /&gt;
              &lt;/basicHttpBinding&gt;
          &lt;/bindings&gt;
          &lt;client&gt;
              &lt;endpoint address="http://localhost:53673/Service1.svc" binding="basicHttpBinding"
                  bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                  name="BasicHttpBinding_IService1" /&gt;
          &lt;/client&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And based on the suggestion, I change it to:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;startup&gt; 
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
      &lt;system.serviceModel&gt;
          &lt;bindings&gt;
              &lt;basicHttpsBinding&gt;
                  &lt;binding name="BasicHttpsBinding_IService1" /&gt;
              &lt;/basicHttpsBinding&gt;
          &lt;/bindings&gt;
          &lt;client&gt;
              &lt;endpoint address="https://localhost:53673/Service1.svc" binding="basicHttpsBinding"
                  bindingConfiguration="BasicHttpsBinding_IService1" contract="ServiceReference1.IService1"
                  name="BasicHttpsBinding_IService1" /&gt;
          &lt;/client&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Now, I got another error:</p>
  
  <pre><code>An unhandled exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll
  
  Additional information: An error occurred while making the HTTP request to https://localhost:53673/Service1.svc. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.
  </code></pre>
  
  <p>I don't think there is a problem with the certificate if I can launch the site from browser. In addition, I use self-signed certificate and client and server are on the same machine. I am thinking if it is that I cannot change the client's app.config directly and there is something wrong with the configuration of the service? I noticed that every time I update the service in the client service reference, the http binding will appear in the app.config. I would like to know what is the right way to deal with it?</p>