【问题标题】:WCF Data Service - iOS oData SDK IssuesWCF 数据服务 - iOS oData SDK 问题
【发布时间】:2011-11-25 04:13:33
【问题描述】:

我有一个与 C# WCF 数据服务和 iOS 客户端(使用 oData SDK)有关的奇怪问题。

这是我的 WCF 数据服务的简化版本:

using System;
using System.Data.Services;
using System.Data.Services.Common;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Web;
using FootballFeedsModel;

[ServiceBehavior]
public class FootballFeeds : DataService<FootballFeedsEntities > {
    // This method is called only once to initialize service-wide policies.
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetServiceOperationAccessRule("TeamsList", ServiceOperationRights.All);

        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    }
    [WebGet (ResponseFormat = WebMessageFormat.Json)]
    public IQueryable<Team> TeamsList(){
        return new FootballFeedsEntities().Teams.AsQueryable();
    }
}

服务当前是实时托管的,因此我可以确认我可以浏览到它,并浏览实体集合等。

我在我的 iOS 应用程序中编写了以下代码,只是为了测试与服务的连接:

    FootballFeedsEntities *proxy = [[FootballFeedsEntities alloc] 
    initWithUri:@"http://testwebserver.com/Services/FootballFeeds.svc" 
credential:nil];

        DataServiceQuery *query = [proxy teams];

        QueryOperationResponse *response = [query execute];

            resultArray =[[response getResult] retain];

        if([resultArray count] > 0 )
            {
            NSLog(@"Got Results");
        }

但是,在我得到 200 状态码后,连接就挂了(数据库中只有 5 个项目,所以我知道这不是数据大小的问题)。

但是,如果我将代码更改为从 oData Northwind 服务读取,(并为此服务添加由 odatagen 生成的文件)

    NorthwindEntities *proxy = [[NorthwindEntities alloc]
 initWithUri:@"http://services.odata.org/Northwind/Northwind.svc"
 credential:nil];

    DataServiceQuery *query = [proxy teams];

    QueryOperationResponse *response = [query execute];

    resultArray =[[response getResult] retain];
    NSLog(@"Got Results");
    if([resultArray count] > 0 )
    {
        NSLog(@"Got Results");
    }

我得到了预期的结果。 我不知道我的拼图缺少什么,所以任何指针都会很有帮助。

问候

【问题讨论】:

    标签: c# ios4 odata wcf-data-services


    【解决方案1】:

    在回答我自己的问题时,我只是通过修改以下代码来修复代码,我在这里添加以防其他人有同样的问题。

    [WebGet(ResponseFormat = WebMessageFormat.Json)] 
    public static void InitializeService(DataServiceConfiguration config)     { 
        config.SetEntitySetAccessRule("*", EntitySetRights.All);   
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); 
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
     } 
    

    【讨论】:

    • 天哪,WebGet 在那里做什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 2011-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多