Object hierarchy returned by WCF Service is different than expected

Posted by robalot on Stack Overflow See other posts from Stack Overflow or by robalot
Published on 2010-04-09T12:28:57Z Indexed on 2010/04/09 12:43 UTC
Read the original article Hit count: 382

Filed under:
|
|

Good Day Everyone...

My understanding may be wrong, but I thought once you applied the correct attributes the DataContractSerializer would render fully-qualified instances back to the caller.

The code runs and the objects return. But oddly enough, once I look at the returned objects I noticed the namespacing disappeared and the object-hierarchy being exposed through the (web applications) service reference seems to become "flat" (somehow). Now, I expect this from a web-service…but not through WFC. Of course, my understanding of what WFC can do may be wrong.

...please keep in mind I'm still experimenting with all this.

So my questions are…

Q: Can I do something within the WFC Service to force the namespacing to render through the (service reference) data client proxy?

Q: Or perhaps, am I (merely) consuming the service incorrectly?

Q: Is this even possible?

The service code looks like…

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class DataService : IFishData
{
    public C1FE GetC1FE(Int32 key)
    {
         //… more stuff here …
    }
    public Project GetProject(Int32 key)
    {
      //… more stuff here …
    }
}

[ServiceContract]
[ServiceKnownType(typeof(wcfFISH.StateManagement.C1FE.New))]
[ServiceKnownType(typeof(wcfFISH.StateManagement.Project.New))]
public interface IFishData
{
     [OperationContract]
     C1FE GetC1FE(Int32 key);

     [OperationContract]
     Project GetProject(Int32 key);
}

[DataContract]
[KnownType(typeof(wcfFISH.StateManagement.ObjectState))]
public class Project
{
      [DataMember]
      public wcfFISH.StateManagement.ObjectState ObjectState { get; set; }

      //… more stuff here …
}

[DataContract]
KnownType(typeof(wcfFISH.StateManagement.ObjectState))]
public class C1FE
{
      [DataMember]
      public wcfFISH.StateManagement.ObjectState ObjectState { get; set; }

   //… more stuff here …
}

[DataContract(Namespace = "wcfFISH.StateManagement")]
[KnownType(typeof(wcfFISH.StateManagement.C1FE.New))]
[KnownType(typeof(wcfFISH.StateManagement.Project.New))]
public abstract class ObjectState
{
      //… more stuff here …
}

[DataContract(Namespace = "wcfFISH.StateManagement.C1FE", Name="New")]
[KnownType(typeof(wcfFISH.StateManagement.ObjectState))]
public class New : ObjectState
{
      //… more stuff here …
}

[DataContract(Namespace = "wcfFISH.StateManagement.Project", Name = "New")]
[KnownType(typeof(wcfFISH.StateManagement.ObjectState))]
public class New : ObjectState
{
      //… more stuff here …
}

The web application code looks like…

public partial class Fish_Invite : BaseForm
{
    protected void btnTest_Click(object sender, EventArgs e)
    {
       Project project = new Project();
       project.Get(base.ProjectKey, base.AsOf);

       mappers.Project mapProject = new mappers.Project();

       srFish.Project fishProject = new srFish.Project();
       srFish.FishDataClient fishService = new srFish.FishDataClient();

       mapProject.MapTo(project, fishProject);

       fishProject = fishService.AddProject(fishProject, IUser.UserName);

       project = null;
    }
}

In case I’m not being clear…

The issue arises as there is a difference in (the name spacing) that I expect to see (returned) is different from what is actually returned.

fishProject.ObjectState should look like...

srFish.StateManagement.Project.New

fishC1FE.ObjectState should look like...

srFish.StateManagement.C1FE.New

fishProject.ObjectState looks like...

srFish.New1

fishC1FE.ObjectState looks like...

srFish.New

…“Help me Obi-Wan Kenobi, you’re my only hope!”

© Stack Overflow or respective owner

Related posts about wcf

Related posts about wcfservice