Reputation: 2028
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.
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).
With this, there are created three classes in the Context.tt, AnswerSet, QuestionSet and Context.cs
the QuestionSet class looks as follows:
public partial class QuestionSet
{
public QuestionSet()
{
this.AnswerSets = new HashSet<AnswerSet>();
}
public int Id { get; set; }
public string Quest { get; set; }
public virtual ICollection<AnswerSet> AnswerSets { get; set; }
}}
My Service looks like that:
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);
}
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?? ..
this is the error that the wcf client shows:
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.
The underlying connection was closed: The connection was closed unexpectedly.
Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
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)Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at INeuralnetworkService.DoWorkQuest() at NeuralnetworkServiceClient.DoWorkQuest()
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)
does anybody can help me?
@John Saunders, thank you for your answer. i took a look to the eventviewer of windows.
So, the error is: that the ASP compatibility is on, i should turn of or allow or requered :) see message:
$
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..
I added now the follwing code to my service:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
but it still wont work..
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.
.....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
the Event LOG contains the following:
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'.. ---> 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
But is this normal that i can not send an entity through WCF? but a string from it is sendable?
br damir
*EDIT*
Thanks to everybody for helping me. I learnd a lot through this problem and from your help. Thank you.
Upvotes: 2
Views: 2030
Reputation: 123
The entities are probably still in a proxy format. The dynamic proxies automatically generated by Entity Framework do not transfer well over the wire.
To turn this off, on the service make sure you set ProxyCreatedEnabled to false:
yourContextObject.Configuration.ProxyCreationEnabled = false;
Upvotes: 2
Reputation: 55022
you need to install asp.net.
you should look for this process for .net 4 or whatever version you are using.
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727
Upvotes: 1