无法从 WCF 数据服务获取数据

发布于 2024-12-08 20:51:40 字数 2592 浏览 0 评论 0原文

我设置了 WCF 数据服务 http://localhost:65432/YeagerTechWcfService.svc ,当我运行它时,我得到下面的预期输出:

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<service xmlns="http://www.w3.org/2007/app" xmlns:app="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xml:base="http://localhost:65432/YeagerTechWcfService.svc/"> 
   <workspace> 
       <atom:title>Default</atom:title> 
       <collection href="Categories"> 
          <atom:title>Categories</atom:title> 
       </collection> 
       <collection href="Customers"> 
           <atom:title>Customers</atom:title> 
       </collection> 
       <collection href="Priorities"> 
           <atom:title>Priorities</atom:title> 
       </collection> 
       <collection href="Projects"> 
           <atom:title>Projects</atom:title> 
       </collection> 
       <collection href="Status"> 
           <atom:title>Status</atom:title> 
       </collection> 
       <collection href="TimeTrackings"> 
           <atom:title>TimeTrackings</atom:title> 
       </collection>
    </workspace> 
</service>

但是,执行以下方法后,我在脚本中遇到 js 运行时错误: httpErrorPagesScripts.js 通过测试时浏览器:

var bElement = document.createElement("A");
bElement.innerText = L_GOBACK_TEXT ;
bElement.href = "javascript:history.back();";
goBackContainer.appendChild(bElement); 

在我输入以下查询后,正在执行的方法如下:

http://localhost:65432/YeagerTechWcfService.svc/Customers


public QueryOperationResponse<Customer> GetCustomers()
{
        YeagerTechEntities DbContext = new YeagerTechEntities();

        YeagerTechModel.YeagerTechEntities db = new YeagerTechModel.YeagerTechEntities();

        DataServiceQuery<Customer> query = (DataServiceQuery<Customer>)
                from customer in db.Customers
                    where customer.CustomerID > 0
                    select customer;

        QueryOperationResponse<Customer> items = (QueryOperationResponse<Customer>)query.Execute();

        db.Dispose();

        return items;
    }

即使我在上述方法中设置了断点,它也不会在那里停止。我只知道我在地址栏上提交查询后,就进入这个方法,然后弹出来执行那个js错误。我确信我错过了一些东西......有人可以帮忙吗?

仅从数据库返回 1 条记录,因此获取的行数不是问题...

请注意,使用常规 WCF 对 EF ORM 模型成功执行了相同类型的查询应用服务。只是当我尝试使用 WCF 数据服务 应用相同的查询时,我收到了错误。

I set up a WCF Data Service http://localhost:65432/YeagerTechWcfService.svc and when I run it, I get the expected output below:

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<service xmlns="http://www.w3.org/2007/app" xmlns:app="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xml:base="http://localhost:65432/YeagerTechWcfService.svc/"> 
   <workspace> 
       <atom:title>Default</atom:title> 
       <collection href="Categories"> 
          <atom:title>Categories</atom:title> 
       </collection> 
       <collection href="Customers"> 
           <atom:title>Customers</atom:title> 
       </collection> 
       <collection href="Priorities"> 
           <atom:title>Priorities</atom:title> 
       </collection> 
       <collection href="Projects"> 
           <atom:title>Projects</atom:title> 
       </collection> 
       <collection href="Status"> 
           <atom:title>Status</atom:title> 
       </collection> 
       <collection href="TimeTrackings"> 
           <atom:title>TimeTrackings</atom:title> 
       </collection>
    </workspace> 
</service>

However, after executing the below method, I'm getting a js runtime error in the script: httpErrorPagesScripts.js when testing it out via the browser:

var bElement = document.createElement("A");
bElement.innerText = L_GOBACK_TEXT ;
bElement.href = "javascript:history.back();";
goBackContainer.appendChild(bElement); 

The method that is executing is below after I put in the following query:

http://localhost:65432/YeagerTechWcfService.svc/Customers


public QueryOperationResponse<Customer> GetCustomers()
{
        YeagerTechEntities DbContext = new YeagerTechEntities();

        YeagerTechModel.YeagerTechEntities db = new YeagerTechModel.YeagerTechEntities();

        DataServiceQuery<Customer> query = (DataServiceQuery<Customer>)
                from customer in db.Customers
                    where customer.CustomerID > 0
                    select customer;

        QueryOperationResponse<Customer> items = (QueryOperationResponse<Customer>)query.Execute();

        db.Dispose();

        return items;
    }

Even if I set a breakpoint in the above method, it doesn't stop there. I just know that after I submit the query on the address bar, it goes into this method, and then pops out and executes that js error. I'm sure that I'm missing something..... Can someone help?

There is only 1 record coming back from the database, so the number of rows fetched is not an issue...

Note that this same type of query is successfully executed against an EF ORM model with a regular WCF Application Service. It's just that when I try to apply the same query using a WCF Data Service, I'm getting the error.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文