title: HTTP status 404 error while calling WCF service from ASP.NET client after web service migration from ASP.NET to WCF
body: <p>Currently we have a number of customers which use ASP.NET clients to call our various ASP.NET Web Services. We would like to migrate web services to WCF without touching customers' clients and their proxies. In addition we want to avoid using IIS for hosting services.</p>
  
  <p>I've prepared simple prototype to examine if we are able to achieve such migration. This prototype works fine if only a simple namespace of web service is in use e.g. <em>test.com</em>. But because our ASP.NET services have namespaces like <em>test.com/app1</em>, <em>test.com/app2</em> etc we need to build WCF services accordingly. Unfortunately when such address is used I get <em>HTTP status 404</em> error while calling service's method.</p>
  
  <p>After a few days of struggling I'm not sure if such migration is possible without hosting services on IIS (the IIS solution is <a href="http://msdn.microsoft.com/en-us/library/aa738697(v=vs.100).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa738697(v=vs.100).aspx</a>).</p>
  
  <p>Please, follow steps which I've done to prepare working prototype (with namespace <em>test.com</em>) and tell me where I'm wrong for extended namespace (like <em>test.com/app</em>).</p>
  
  <p>1.
  Initial ASP.NET web service:  </p>
  
  <pre><code>[WebService(Namespace = "http://test.com")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.ComponentModel.ToolboxItem(false)]
  public class AspNetWebService : WebService
  {
    private static int _counter = 0;
    [WebMethod]
    public int Increment()
    {
      return _counter++;
    }
  }
  </code></pre>
  
  <p>2.
  Deploy web service on IIS 7.0.</p>
  
  <p>3.
  Create simple ASP.NET client and generate proxy to web service (from step 1) by adding web reference in Visual Studio 2012 to asmx file of web service.</p>
  
  <p>4.
  Client calls Increment method properly, so I will not change this client to check if I may call WCF service.</p>
  
  <p>5.
  Create WCF service.  </p>
  
  <p>Contract:</p>
  
  <pre><code>[ServiceContract(Name = "IncrementService", Namespace = "http://test.com")]
  public interface IIncrementService
  {
    [OperationContract(Action = "http://test.com/Increment")]
    int Increment();
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
  public class IncrementService : IIncrementService
  {
    private static int _counter = 0;
    public int Increment()
    {
      return _counter++;
    }
  }
  </code></pre>
  
  <p>Self hosted in:</p>
  
  <pre><code>static void Main(string[] args)
  {
       const string httpAddress = "http://test.com";
       var host = new ServiceHost(typeof(IncrementService), new Uri(httpAddress));
       try
       {
         var metadataBehavior = host.Description.Behaviors.Find&lt;ServiceMetadataBehavior&gt;();
         if (metadataBehavior == null)
           metadataBehavior = new ServiceMetadataBehavior();
         metadataBehavior.HttpGetEnabled = true;
         host.Description.Behaviors.Add(metadataBehavior);
  
         var httpBinding = new BasicHttpBinding();
         httpBinding.Security.Mode = BasicHttpSecurityMode.None;
         httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
         host.AddServiceEndpoint(typeof(IIncrementService), httpBinding, httpAddress);
  
         host.Open();
         Console.ReadLine();
         host.Close();
       }
       catch (Exception ex)
       {
         Console.WriteLine("An exception occurred: {0}", ex.Message);
         host.Abort();
       }
  }
  </code></pre>
  
  <p>6.
  Switch off IIS to be sure that ASP.NET web service doesn't work and start WCF service.</p>
  
  <p>7.
  Run the same client as before (without any changes or proxy regenerations) - it calls Increment properly. </p>
  
  <p>So far so good... now I extend namespace.</p>
  
  <p>8.
  Add app name to namespace in ASP.NET web service as following: </p>
  
  <pre><code>[WebService(Namespace = "http://test.com/app")]
  </code></pre>
  
  <ol start="9">
  <li><p>Switch on IIS again, switch off WCF service, regenerate proxy for client to work with new namespace - it calls Increment method properly again.</p></li>
  <li><p>Change namespaces in WCF service as following:</p></li>
  </ol>
  
  <p>Contract:</p>
  
  <pre><code>[ServiceContract(Name = "IncrementService", Namespace = "http://test.com/app")]
  public interface IIncrementService
  {
    [OperationContract(Action = "http://test.com/app/Increment")]
    int Increment();
  }
  </code></pre>
  
  <p>In host application change httpAddress:</p>
  
  <pre><code>const string httpAddress = "http://test.com/app";
  </code></pre>
  
  <ol start="11">
  <li><p>Switch off IIS, start WCF.</p></li>
  <li><p>Try to call Increment method from the same client - exception occurs: The request failed with HTTP status 404: Not Found.</p></li>
  </ol>
  
  <p>If I do not change httpAddress in step 10, then all works fine, but in such case I can host only one service on <em>test.com</em> domain. So this solution is not sufficient for us.</p>