title: WCF SOAP + REST/Json service without .svc - do I have twice the number of service factories?
body: <p>Ok, so I wanted to have a single service exposed as a SOAP as well as REST (Json) end point. Since it's off the "WCF Service Application" template, I have a web.config and I added the following into the ...</p>
  
  <p><strong>web.config</strong></p>
  
  <pre><code>&lt;configuration&gt;
    ...
    &lt;system.serviceModel&gt;
      &lt;services&gt;
          &lt;service name="MySvcClass"&gt;
              &lt;endpoint address="" binding="webHttpBinding" contract="MySvcInterfaceClass" behaviorConfiguration="restBehavior" /&gt;
              &lt;endpoint address="soap" binding="basicHttpBinding" contract="MySvcInterfaceClass" /&gt;
              &lt;endpoint address="mex"  binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
          &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
          &lt;serviceBehaviors&gt;
              &lt;behavior&gt;
                  &lt;serviceMetadata httpGetEnabled="true"/&gt;
                  &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
              &lt;/behavior&gt;
          &lt;/serviceBehaviors&gt;
          &lt;endpointBehaviors&gt;
              &lt;behavior name="restBehavior"&gt;
                  &lt;webHttp helpEnabled="true"/&gt;
              &lt;/behavior&gt;
          &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/&gt;
    &lt;/system.serviceModel&gt;
    ...
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Assuming the MySvcClass class is implemented within \MySvcClass.svc, the above exposes ...</p>
  
  <p><strong>Original Endpoints</strong></p>
  
  <p><code>localhost\MySvcClass.svc\</code> (rest endpoint)</p>
  
  <p><code>localhost\MySvcClass.svc\mex</code> (Metadata Exchange to the use the SOAP end point below)</p>
  
  <p><code>localhost\MySvcClass.svc\soap</code> (soap endpoint)</p>
  
  <p>So far, so good (I think!).</p>
  
  <p>Then I wanted to get rid of the ugly ".svc" seen in the paths above. So I followed this <a href="http://blogs.msdn.com/b/rjacobs/archive/2010/04/05/using-system-web-routing-with-data-services-odata.aspx" rel="nofollow">MSDN blog post</a> and had this in my ...</p>
  
  <p><strong>global.asax</strong></p>
  
  <pre><code>void Application_Start(object sender, EventArgs e)
  {       
      RouteTable.Routes.Add(new ServiceRoute("MySvcClass", new WebServiceHostFactory(), typeof(MySvcClass)));
  }
  </code></pre>
  
  <p>Interestingly, when I put a breakpoint inside Application_Start, VS2010 doesn't hit this particular breakpoint - even when I stop->start debugging or stop->start the IIS application pool. Bizarre! Anyway, back to the point, I can now access the services the above listed endpoints AND</p>
  
  <p><strong>Cleaner Endpoints</strong></p>
  
  <p><code>localhost\MySvcClass\</code> (rest endpoint)</p>
  
  <p><code>localhost\MySvcClass\mex</code> (Metadata Exchange to the use the SOAP end point below)</p>
  
  <p><code>localhost\MySvcClass\soap</code> (soap endpoint)</p>
  
  <p><strong>Questions</strong></p>
  
  <ol>
  <li>Am I having TWO service factories? One from the web.config and the other from the global.asax? If yes, how can I avoid it while still having clean URLs (without .svc). I don't really need the ones with .svc in the path ...</li>
  <li>I dislike cluttered web.configs, so is there any way I can move the above SOAP and REST configuration from the XML (web.config) into code (eg global.asax?) ? I know how to move the REST only end point - wipe out  in the web.config, leave global.asax as is. However doing that kills the SOAP endpoint.</li>
  </ol>
  
  <p><strong>[Update]</strong>
  I had tried URL rewrites too but this killed the SOAP endpoint while keeping the REST endpoint alive. Wht I did was : Used MS's URL Rewrite 2.0 module with this in the web.config</p>
  
  <pre><code>&lt;system.webServer&gt; 
    &lt;modules runAllManagedModulesForAllRequests="true"/&gt; 
    &lt;rewrite&gt; 
      &lt;rules&gt; 
        &lt;rule name="RemoveSvcExt" stopProcessing="true"&gt; 
          &lt;match url="^MySvcClass(.*)$" /&gt; 
          &lt;action type="Rewrite" url="MySvcClass.svc{R:1}" /&gt; 
        &lt;/rule&gt; 
      &lt;/rules&gt; 
    &lt;/rewrite&gt; 
  &lt;/system.webServer&gt; 
  </code></pre>
  
  <p>However, this leaves the web app in some inconsistent state because there are some parts which still stick to the <code>.svc</code> URLs. eg: the HTML help page at the service endpoint shows <code>svcutil.exe http://localhost/MySvcClass.svc?wsdl</code> Even the WSDL at the clean location at <code>http://localhost/MySvcClass?wsdl</code> makes references to <code>http://localhost/MySvcClass.svc</code> inside it - this effectively kills the SOAP endpoint.</p>
  
  <p>That's why I think ($0.02) the rewrite is just a kludge. Sigh, at this point I'm fighting with the framework to get stuff done. And it feels such a time burner ...</p>