Wcf数据服务服务操作

发布于 2024-11-27 17:20:09 字数 2986 浏览 1 评论 0原文

当我使用错误消息后面的代码运行 wcf 数据服务时出现错误:

"The server encountered an error processing the request. See server logs for more details."

代码:

public class WcfDataService1 : DataService<Entities1>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("GetData", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }

        [WebGet()]
        public IQueryable GetData(int Id)
        {

            if (assayId > 0)
            {
                var query = from a in this.CurrentDataSource.Entity
                            where a.ID == Id
                            select a;

                return query;
            }
            else
                throw new DataServiceException(400, "ID is not valid");

        }


    }

当我不从操作中返回任何内容时,相同的代码会起作用。

更新:服务器日志显示:

"WebHost failed to process a request.
 Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/44530215
 Exception: System.ServiceModel.ServiceActivationException: The service '/MyWcfDataService.svc' cannot be activated due to an exception during compilation.  The exception message is: The type 'MyWcfDataService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.. ---> System.InvalidOperationException: The type 'MyWcfDataService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
   at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
 Process Name: WebDev.WebServer40
 Process ID: 1124

For more information, see Help and Support Center at 

任何人都可以帮我解决问题吗?

另外,如果我想公开我自己的实体,而不是 EF 创建的实体,该怎么做……有什么想法吗?

Getting error when I run the wcf data service with the code following the error message:

"The server encountered an error processing the request. See server logs for more details."

Code:

public class WcfDataService1 : DataService<Entities1>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("GetData", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }

        [WebGet()]
        public IQueryable GetData(int Id)
        {

            if (assayId > 0)
            {
                var query = from a in this.CurrentDataSource.Entity
                            where a.ID == Id
                            select a;

                return query;
            }
            else
                throw new DataServiceException(400, "ID is not valid");

        }


    }

The same code works when I dont return anything from the operation.

UPDATE: The server logs say:

"WebHost failed to process a request.
 Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/44530215
 Exception: System.ServiceModel.ServiceActivationException: The service '/MyWcfDataService.svc' cannot be activated due to an exception during compilation.  The exception message is: The type 'MyWcfDataService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.. ---> System.InvalidOperationException: The type 'MyWcfDataService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
   at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
 Process Name: WebDev.WebServer40
 Process ID: 1124

For more information, see Help and Support Center at 

Can anyone please help me with the solution.

Also, if I want to expose my own entity and not the one created by EF, how to go about doing that.. any ideas??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2024-12-04 17:20:09

只需将返回类型修改为

IQueryable 即可。

Just modified the return type to

IQueryable<Entity> and it worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文