简体   繁体   English

WCF数据服务-iOS oData SDK问题

[英]WCF Data Service - iOS oData SDK Issues

I have a strange problem relating to a C# WCF Data Service, and a iOS client (using the oData SDK). 我有一个与C#WCF数据服务和iOS客户端(使用oData SDK)有关的奇怪问题。

Here is a simplified version of my WCF Data Service: 这是我的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();
    }
}

The services is currently hosted live, so I can confirm that I can browse to it, and navigate through the Entity collection etc. 这些服务当前是实时托管的,因此我可以确认可以浏览到该服务,并浏览Entity集合等。

I wrote the following code in my iOS application simply to test the connection to the service: 我在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");
        }

However the connection simply hangs after I get a 200 status code (there are only 5 items in the database, so I know it is not an issue with the size of the data). 但是,当我收到200状态代码后,连接就简单地挂起(数据库中只有5个项目,因此我知道这与数据大小无关)。

However if I change the code to read from the oData Northwind service, (and add files for this service produced by odatagen) 但是,如果我更改代码以从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");
    }

I get results as expected. 我得到预期的结果。 I am at a loss as to what the missing piece of my jigsaw is, so any pointers would be really helpful. 我对拼图中缺少的部分不知所措,因此任何指针都将非常有帮助。

Regards 问候

In answer to my own question, I fixed the code simply by modifying the below, I add here in case anyone else has the same issue. 为了回答我自己的问题,我仅通过修改以下内容来修复了代码,以防其他人遇到相同的问题,请在此处添加代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM