title: WCF hosting issue within Windows service
body: <p>I have created a REST WCF service.</p>
  
  <p>First i have hosted in Console app, it was working OK.</p>
  
  <p>Then i have hosted it in Windows service. It is throwing various errors</p>
  
  <p>Following is the config</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;diagnostics&gt;
    &lt;messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" /&gt;
  &lt;/diagnostics&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="serviceMetadataBehavior"&gt;
        &lt;serviceMetadata /&gt;
      &lt;/behavior&gt;
      &lt;behavior name="restServiceMetaBehavior"&gt;
        &lt;serviceMetadata httpGetEnabled="true" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
      &lt;/behavior&gt;
  
    &lt;/serviceBehaviors&gt;
  
    &lt;endpointBehaviors&gt;
      &lt;behavior name="jsonEndpointBehavior"&gt;
        &lt;enableWebScript /&gt;
      &lt;/behavior&gt;
      &lt;behavior name="wsHttpBinding" /&gt;
    &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  
  &lt;services&gt;
  
  &lt;service behaviorConfiguration="restServiceMetaBehavior" name="StockPriceNotifierServiceImpl.StockNotifierServiceImpl"&gt;
  &lt;!--SOAP endpoint--&gt;
    &lt;endpoint address="net.tcp://localhost:8082/StockPriceService"
        binding="netTcpBinding" bindingConfiguration="" contract="StockPriceNotifierService.IStockNotifierService" /&gt;
    &lt;endpoint address="net.tcp://localhost:8082/StockPriceService/mex" binding="mexTcpBinding" bindingConfiguration=""  contract="IMetadataExchange"/&gt;
  
  
    &lt;!--rest endpoint--&gt;
  
    &lt;endpoint address="http://localhost:8084/StockNotifierService"
        binding="webHttpBinding"  name="webhttp"
        contract="StockPriceNotifierService.IStockNotifierRestService" /&gt;
      &lt;endpoint address="http://localhost:8084/StockNotifierService/mex"
       binding="mexHttpBinding" name="MexWebHttp" contract="IMetadataExchange" /&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have tried to troubleshoot but no success.</p>
  
  <p>Following are the steps taken so far</p>
  
  <ol>
  <li><p>Inital error -> The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address.  Either supply an http base address or set HttpGetUrl to an absolute address.
  Resolution -> <a href="http://social.msdn.microsoft.com/Forums/pl/wcf/thread/2fd858cb-8988-444f-868c-2ceea9cc9705" rel="nofollow">http://social.msdn.microsoft.com/Forums/pl/wcf/thread/2fd858cb-8988-444f-868c-2ceea9cc9705</a>, Specified HttpGetUrl</p></li>
  <li><p>AddressFilter mismatch error ->The message with To 'http://localhost:8084/StockService/MSFT/Price' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
  Resolution -> Added behavior ->[ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)]</p></li>
  <li><p>Now ContractFilter mismatch exception -> System.ServiceModel.FaultException: The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. </p></li>
  </ol>
  
  <p>Seems like i am missing some basics, but no clue so far.</p>
  
  <p>Contracts</p>
  
  <pre><code> [ServiceContract] //REST
    public interface IStockNotifierRestService
    {
      [OperationContract]
      [WebGet(UriTemplate = Routing.GetCurrentPriceRoute,
          BodyStyle = WebMessageBodyStyle.Wrapped,
          RequestFormat = WebMessageFormat.Xml,
          ResponseFormat = WebMessageFormat.Json
          )]
      double GetCurrentPrice(string symbol);
  
  
  
   [ServiceContract]  //SOAP
   public interface IStockNotifierService:IStockNotifierRestService
    {
      [OperationContract]
      double GetPrice(String symbolname, DateTime timestamp);
    }
  </code></pre>
  
  <p>Implementation</p>
  
  <pre><code>[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, 
          InstanceContextMode= InstanceContextMode.Single, AddressFilterMode=AddressFilterMode.Any)]
  
      [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
      public class StockNotifierServiceImpl:IStockNotifierService
      {
  
  
          public double GetPrice(string symbolname, DateTime timestamp)
          {
              return 12.0;
          }
  
          public double GetCurrentPrice(string symbolname)
          {
              return 13.0;
          }
     }
  </code></pre>