我有一个问题从WCF服务获取对象。 我创建了一个WCF项目和一个Silverlight项目。在SQL Express中,我有一个带有两个表的数据库:QuestionSet和AnswerSet。从WCF服务获取实体
所以,我WCF项目我添加了一个新的项目,ADO.NET实体数据模型添加我的数据库模型。然后我从那里创建一个代码生成项目(ADO.NET DbContext生成器)。 (我使用实体框架4.1)。
有了这个,还有在Context.tt,AnswerSet,QuestionSet和Context.cs创建三类
的QuestionSet类如下所示:
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; }
}}
我的服务看起来像这样:
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);
}
当我现在启动服务时,WCF测试客户端启动。 doWork可以很好地与我自己创建的类 一起工作。但另一种方法doWorkQuest不适用。它工作时,我改变返回值的DTO类,并强制.. ..但为什么没有与从数据库中创建的实体工作? ..
这是WCF客户端显示了错误:
无法调用服务。可能的原因:服务处于脱机状态或无法访问;客户端配置不匹配 代理;现有的代理无效。有关更多详细信息,请参阅 的堆栈跟踪。您可以尝试通过启动新代理,将 恢复为默认配置或刷新服务来进行恢复。
底层连接已关闭:连接意外关闭。
服务器堆栈跟踪:在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(引发WebException 引发WebException,HttpWebRequest的请求,HttpAbortReason abortReason)
在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度 超时)在 System.ServiceModel.Channels.RequestChannel.Request(消息消息,时间跨度 超时)处 System.ServiceModel.Channels.Serv System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息 消息,时间跨度超时) iceChannel.Call在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 包括MethodCall,ProxyOperationRuntime操作)在 系统(字符串动作, 布尔单向,ProxyOperationRuntime操作,对象[]插件, 对象[]奏,时间跨度超时) .ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天 消息)在异常重新抛出[0]:在在 System.Runtime System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天 reqMsg,即时聊天retMsg) .Remoting.Proxies.RealProxy.PrivateInvoke(MessageData & msgData,Int32类型)在INeuralnetworkService.DoWorkQuest() NeuralnetworkServiceClient。DoWorkQuest()
内部异常:底层连接已关闭:连接 意外关闭。在System.Net.HttpWebRequest.GetResponse() 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度 超时)
没有任何人能帮助我吗?
@John Saunders,谢谢你的回答。我看了一下windows的eventviewer。
所以,错误的是:该ASP兼容性上,我应该打开或允许或requered :)看到消息:
$
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..
我现在添加了follwing代码到我的服务:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
,但它仍然无法正常工作..
我试图安装aspnet_regiis.exe。但安装检测到错误。见日志。 但我检查了IIS配置,DefaultAPPPool和其他人是.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
事件日志包含以下内容:
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
但是,这是正常的,我无法通过WCF发送实体?但从它的字符串是可发送的?
BR 达米尔
* 编辑 *
感谢大家对我的帮助。我通过这个问题和你的帮助学到了很多东西。谢谢。
这个问题是在服务中发生。查看服务器上的事件日志以查看发生了什么。 –
约翰,谢谢你..所以我今后我知道我必须先看看我发布的东西之前.. – damir