DataContract not available at WCF client service reference

强颜欢笑 提交于 2019-12-08 07:02:31

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();
}

Explanation

You can verify it by using Svcutil.exe.

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

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.

PROXY class for Room:

[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;
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!