DataContract不提供WCF客户服务参考

问题描述:

我有这样的数据合同,我的WCF服务

I have this Data contract in my WCF service

[DataContract]
public class Department
{
    [DataMember]
    public List<Section> Sections { get; set; }
}


[DataContract]
public class Section
{
    [DataMember]
    public List<Room> Rooms { get; set; }
}

[DataContract]
public class Room
{
    [DataMember]
    public uint RoomId { get; set; }
}

当我在客户端应用程序中引用我的服务,我只看到房类,任何机构可以解释我为什么部和科类合同不提供客户端。

When I reference my service in client application,I only see Room class,Can any body explain me why contract for Department and Section class are not available at client side.

在你的的ServiceContract 接口添加相关的这将使和一个单人操作部分你的客户端应用程序可见。

In your ServiceContract interface add one single operation related to Department which will make Department and Section visible to your client application.

由于系包含节的列表,它会暴露部分为好。

Since Department contains list of Sections, it will expose Section as well.

[ServiceContract]
public interface IService1
{
    [OperationContract]
    Room GetRoom();

    [OperationContract]
    List<Department> GetDepartments();
}



说明



您可以通过使用 svcutil.exe的的验证。

如果用户定义的类没有经营合同的存在,它的定义不会代理类排放生成使用SvcUtil工具。

If no operation contract exist for user defined classes, its definition won't emit in proxy class generated using Svcutil.

如果我忽略第二承包经营合同,只有客房类时发出的代理类。所以,你需要对你的类,使其对客户可见ATLEAST一个操作合约

If I omit second operation contract of Department, only Room class gets emitted in proxy class. So, you need to have atleast one operation contract on your class to make it visible to your client.

有关房代理类:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", 
                                                  "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Room", 
             Namespace="http://schemas.datacontract.org/2004/07/DummyService")]
public partial class Room : object,
                System.Runtime.Serialization.IExtensibleDataObject
{        
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;        
    private uint RoomIdField;        
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData
    {
        get
        {
            return this.extensionDataField;
        }
        set
        {
            this.extensionDataField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public uint RoomId
    {
        get
        {
            return this.RoomIdField;
        }
        set
        {
            this.RoomIdField = value;
        }
    }
}