DataContract不提供WCF客户服务参考 [英] DataContract not available at WCF client service reference

查看:171
本文介绍了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;
        }
    }
}

这篇关于DataContract不提供WCF客户服务参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆