title: Get Entity from WCF Service
body: <p>i have a problem to get an object from a WCF Service.
  I created a WCF project and a Silverlight project. 
  in SQL express i have a database with two tables: QuestionSet and AnswerSet.</p>
  
  <p>So, i the WCF project i added my database model by adding a new item, the ADO.NET Entity Data Model. Then i creted from there an Code Generation Item (ADO.NET DbContext Generator). (Im using Entity Framework 4.1).</p>
  
  <p>With this, there are created three classes in the Context.tt, AnswerSet, QuestionSet and Context.cs</p>
  
  <p>the QuestionSet class looks as follows:</p>
  
  <pre><code>public partial class QuestionSet
  {
      public QuestionSet()
      {
          this.AnswerSets = new HashSet&lt;AnswerSet&gt;();
      }
  
  
      public int Id { get; set; }
  
      public string Quest { get; set; }
  
      public virtual ICollection&lt;AnswerSet&gt; AnswerSets { get; set; }
  }}
  </code></pre>
  
  <p>My Service looks like that:</p>
  
  <pre><code>    QuestionnairedbEntities db = new QuestionnairedbEntities();
  
      public MyOwnClass DoWork()
      {
          MyOwnClass n = new MyOwnClass ();
          n.Name = "Name of the Class";
          return n;
      }
  
      public QuestionSet DoWorkQuest()
      {
          QuestionSetDTO qsd = new QuestionSetDTO();
          return db.QuestionSets.Find(11);
      }
  </code></pre>
  
  <p>and when i now start the service, the WCF test client starts. The method doWork works fine
  with my own created class. but the other method, doWorkQuest works not. it works when i change the return value to a DTO class and cast that.. but why isnt working with the entity created from the database?? ..</p>
  
  <p>this is the error that the wcf client shows:</p>
  
  <blockquote>
    <p>Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match
    the proxy; the existing proxy is invalid. Refer to the stack trace for
    more detail. You can try to recover by starting a new proxy, restoring
    to default configuration, or refreshing the service.</p>
    
    <p>The underlying connection was closed: The connection was closed unexpectedly.</p>
    
    <p>Server stack trace:     at
    System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException
    webException, HttpWebRequest request, HttpAbortReason abortReason)<br>
    at
    System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
    timeout)    at
    System.ServiceModel.Channels.RequestChannel.Request(Message message,
    TimeSpan timeout)    at
    System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message
    message, TimeSpan timeout)    at
    System.ServiceModel.Channels.ServiceChannel.Call(String action,
    Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
    Object[] outs, TimeSpan timeout)    at
    System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
    methodCall, ProxyOperationRuntime operation)    at
    System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
    message)</p>
    
    <p>Exception rethrown at [0]:     at
    System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
    reqMsg, IMessage retMsg)    at
    System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp;
    msgData, Int32 type)    at INeuralnetworkService.DoWorkQuest()    at
    NeuralnetworkServiceClient.DoWorkQuest()</p>
    
    <p>Inner Exception: The underlying connection was closed: The connection
    was closed unexpectedly.    at System.Net.HttpWebRequest.GetResponse()
    at
    System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
    timeout)</p>
  </blockquote>
  
  <p>does anybody can help me? </p>
  
  <hr>
  
  <p>@John Saunders, thank you for your answer. i took a look to the eventviewer of windows.</p>
  
  <p>So, the error is: that the ASP compatibility is on, i should turn of or allow or requered :) see message: </p>
  
  <p>$</p>
  
  <pre><code>    The service cannot be activated because it requires ASP.NET compatibility. 
      ASP.NET compatibility is not enabled for this application. Either enable ASP.NET
      compatibility in web.config or set 
      thAspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode
      property to a value other than Required.. 
  </code></pre>
  
  <p>I added now the follwing code to my service:</p>
  
  <pre><code>    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  </code></pre>
  
  <p>but it still wont work..</p>
  
  <hr>
  
  <p>i tried to install aspnet_regiis.exe. but the installation detects an Error. See log.
  But i checked the IIS Configuration, the DefaultAPPPool and others are the .NET Framework 4.0.30319.</p>
  
  <pre><code>.....2011-11-07 08:15:57        Success     Getting all client file dirs and paths
  2011-11-07 08:15:57     Starting    Creating list of client site scripts dirs
  2011-11-07 08:15:57         Starting    Creating directory: C:\inetpub\wwwroot\aspnet_client
  2011-11-07 08:15:57         Failure     Creating directory: C:\inetpub\wwwroot\aspnet_client: CreateDirectoryInternal failed with HRESULT 80070003: 'The system cannot find the path specified.  '
  2011-11-07 08:15:57     Failure     Creating list of client site scripts dirs: CreateSiteClientScriptDir failed with HRESULT 80070003: 'The system cannot find the path specified.  '
  2011-11-07 08:15:57 Failure     Setting up client script files for website:*: Setting up client script files for website: failed with HRESULT 80070003: 'The system cannot find the path specified.  '
  2011-11-07 08:15:57 Starting    Starting service: aspnet_state
  2011-11-07 08:15:57 Success     Starting service: aspnet_state
  </code></pre>
  
  <p>the Event LOG contains the following:</p>
  
  <pre><code>WebHost failed to process a request.
   Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/62476613
   Exception: System.ServiceModel.ServiceActivationException: The service '/NeuralnetworkService.svc' cannot be activated due to an exception during compilation.  The exception message is: The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'.. ---&gt; System.InvalidOperationException: The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'.
     at System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateCompatibilityRequirements(AspNetCompatibilityRequirementsMode compatibilityMode)
     at System.ServiceModel.Activation.AspNetCompatibilityRequirementsAttribute.System.ServiceModel.Description.IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase)
     at System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost)
     at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
     at System.ServiceModel.ServiceHostBase.InitializeRuntime()
     at System.ServiceModel.ServiceHostBase.OnBeginOpen()
     at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
     at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
     at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
     --- End of inner exception stack trace ---
     at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
     at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
   Process Name: WebDev.WebServer40
   Process ID: 4536
  </code></pre>
  
  <p>But is this normal that i can not send an entity through WCF? but a string from it is sendable?</p>
  
  <p>br
  damir</p>
  
  <hr>
  
  <p>*<strong><em>EDIT</em>*</strong></p>
  
  <p>Thanks to everybody for helping me. I learnd a lot through this problem and from your help. Thank you.</p>