relations for web services?

Go To StackoverFlow.com

1

Ok im abit confused how this works with wcf web services.

I have

Programmes (associated with an ID)
Groups (GroupID)
Tags (TagsID)
Users (UserID)

Now lets say Groups are associated with programmes, tags are also associated with groups and users associated to all of them.

For instance Group CSharp is associated with the Programme Computing and the tags webservice and rest but the rest tag is also associated with the Group asp.net how do I return all groups associated with rest?

I have:

IGroupService
IProgrammeService
ITagService
IUsers

How do I associate them and return users belonging to groups and groups related to tags etc?

2012-04-04 19:56
by Garrith Graham
Not sure I understand the question. Are you trying to return all of this information in a single call to the service and wondering what the data contract would be for this type of object graph with all of these relations (and most likely circular references) - Kevin Junghans 2012-04-04 20:13
@KevinJunghans: Put it as an answer - Ladislav Mrnka 2012-04-05 07:55


1

Not sure I understand the question. Are you trying to return all of this information in a single call to the service and wondering what the data contract would be for this type of object graph with all of these relations (and most likely circular references)?

I am probably more confused about the question with the latest bits of information but I will take one last stab at this. I guess what is more confusing is the reference to the term "entities". Is this more of an EF question? If linking is an issue with EF I can only assume a code-first approach is being taken. An example of linking Groups to Tags would look something like this.

    public class Group
    {
        public Group()
        {
            Tags = new List<Tag>();
        }
        public string Name { get; set; }
        public List<Tag> Tags { get; set; }
    }

    public class Tag
    {
        public string Name { get; set; }
    }

To query for all groups that have a specific tag using Linq you would do something like this:

        public List<Group> GetGroups(string TagName)
        {
            List<Group> groups = (from g in _program.Groups where 
             (from t in g.Tags where t.Name == TagName select t).Count() > 0 
              select g).ToList();
            return groups;
        }

If you are using SOAP you would create a proxy in your client and calling the service would look like this:

        string tagName = "rest";
        List<Group> groups = proxy.GetGroups(tagName);

If you are creating a REST API then it would be a simple HTTP request:

http://server/api/GetGroups?tagName=rest

Where the service would return you either XML or JSON representing the Groups.

You list a number of interfaces which I assume contain the operations and data contracts for your services. You do not necessarily need to break your service up by entities and it may also be confusing as to where to put certain operations and data contracts. If a service returns information for multiple entities you will need to repeat data contracts across your service. Breaking service up by entities will not provide much benefit and only make it more difficult for you and any users of the service.

2012-04-05 12:04
by Kevin Junghans
Yes, but not all in one call. Can you provide a small example - Garrith Graham 2012-04-05 12:27
I still do not have enough information to provide an example. What type of bindings are you using in WCF? Is this a RESTful API or are you using SOAP? What is the full definition of your objects with relationships? If you do not want to provide it all in one call, how are you breaking them up? Do you have your operations contract defined? If so what is it? What part have you tried and what exactly are you stuck on - Kevin Junghans 2012-04-05 13:40
I just mean how do you link entitys? Then a small example of how you would call it - Garrith Graham 2012-04-05 17:51
Updated answer based on new information - Kevin Junghans 2012-04-05 19:35
Hey Kevin im abit lost to as to this bit _program.Groups - Garrith Graham 2012-04-06 14:25
"_programs" just represented and instance of Programme and its property Groups is a a collection of Group. It represented the relationship between Programmes and Groups and was just used to contain a collection of Groups for querying - Kevin Junghans 2012-04-06 17:43
Ah I understand this now, could you update your question for a method adding Tags to Groups? As there is no mention of how you would set a tag to a group - Garrith Graham 2012-04-06 19:03
For instance public void AddTagstoGroup (Group group, Tag tag)Garrith Graham 2012-04-06 19:07
Ads