title: WCF Service exception error when try to host in ASP.NET Web Site
body: <p>The following error occurs when trying to browse my .svc file.</p>
  
  <pre><code>An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
  System.NullReferenceException: Object reference not set to an instance of an object.
     at System.ServiceModel.Description.WsdlExporter.CreateWsdlBindingAndPort(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName, Port&amp; wsdlPort, Boolean&amp; newBinding, Boolean&amp; bindingNameWasUniquified)
     at System.ServiceModel.Description.WsdlExporter.ExportEndpoint(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName)
     at System.ServiceModel.Description.WsdlExporter.ExportEndpoints(IEnumerable`1 endpoints, XmlQualifiedName wsdlServiceQName)
     at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
     at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
     at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension)
     at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
     at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message httpGetRequest, String[] queries, Message&amp; replyMessage)
     at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest)
     at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message message)
     at SyncInvokeGet(Object , Object[] , Object[] )
     at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)
     at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
  </code></pre>
  
  <p>Here is my web.config configuration:</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="WcfServiceLib.WcfService"
                 behaviorConfiguration="Default"&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://localhost:8080/WebService"/&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
          &lt;!-- Service Endpoints --&gt;
          &lt;!-- Unless fully qualified, address is relative to base address supplied above --&gt;
          &lt;endpoint address="" binding="wsHttpBinding" contract="WcfServiceContractLib.IWcfContract"/&gt;
          &lt;endpoint address="web" binding="webHttpBinding" contract="WcfServiceContractLib.IWcfContract"
                    behaviorConfiguration="web"/&gt;
          &lt;endpoint address="webJson" binding="webHttpBinding" contract="WcfServiceContractLib.IWcfContract"
                  behaviorConfiguration="webJson"/&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="web"&gt;
            &lt;webHttp defaultOutgoingResponseFormat="Xml" helpEnabled="true"/&gt;
          &lt;/behavior&gt;
          &lt;behavior name="webJson"&gt;
            &lt;webHttp defaultOutgoingResponseFormat="Json" helpEnabled="true"/&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="Default"&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled ="true" /&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Anyone with this similar situation? </p>
  
  <p><em>I should mention that when this is hosted in a console application I use to run tests everything is fine.</em></p>
  
  <p>[EDIT] Same error occurs when trying to load the service in a console app. Not showing the WCF web page where you can see the wsdl info etc...</p>