关于类属性类型的 WCF
好的,我正在构建我的 WCF 服务。我的代理存在问题,无法为具有 ListViewItem 等类型的类甚至我已经定义的类对象生成代码。
下面的两个例子是我试图通过的课程。
示例#1
[DataContract]
public class InvoiceCharges {
#region Property...
private int _invoiceChargeID;
private ListViewItem _listViewItem;
[DataMember]
public int InvoiceChargeID {
get { return _invoiceChargeID; }
set { _invoiceChargeID = value; }
}
[DataMember]
public ListViewItem ListViewItem {
get { return _listViewItem; }
set { _listViewItem = value; }
}
#endregion
示例#2
[DataContract]
public class Users {
#region Properties...
private int _userID;
private Divisions _Division = new Divisions();
[DataMember]
public int UserID {
get { return _userID; }
set { _userID = value; }
}
[DataMember]
public Divisions Division {
get { return _Division; }
set { _Division = value; }
}
在第二个示例中,我很困惑为什么它很难通过它已经看到的我的 Division 类。 WCF 确实可以传递您自己的自定义对象吗?非常感谢任何帮助,我知道在其他平台上为了序列化您自己的自定义对象,您必须对您的类做一些特殊的事情。我不确定 WCF 是否自动处理此问题。
编辑
对此的任何其他帮助仍然值得赞赏。
我还尝试将以下内容添加到 InvoiceCharges 类中,但仍然无法看到代理正确生成。
[KnownType(typeof(ListViewItem))]
此外,这是代理的行为。我正在使用添加服务引用来执行此操作。
查看它如何生成多个“InvoiceCharges”,这都是因为该 ListViewItem。我可以删除它的 DataMember 属性,这很好。
Ok so I am building my WCF service. I am having an issue with my proxy not generating code for classes that have types such as ListViewItem, or even the class objects that I already have defined.
Two examples below are classes that I am trying to pass.
Example #1
[DataContract]
public class InvoiceCharges {
#region Property...
private int _invoiceChargeID;
private ListViewItem _listViewItem;
[DataMember]
public int InvoiceChargeID {
get { return _invoiceChargeID; }
set { _invoiceChargeID = value; }
}
[DataMember]
public ListViewItem ListViewItem {
get { return _listViewItem; }
set { _listViewItem = value; }
}
#endregion
Example #2
[DataContract]
public class Users {
#region Properties...
private int _userID;
private Divisions _Division = new Divisions();
[DataMember]
public int UserID {
get { return _userID; }
set { _userID = value; }
}
[DataMember]
public Divisions Division {
get { return _Division; }
set { _Division = value; }
}
In the 2nd example I am confused why it has a hard time just passing my Division class that it already sees. Surely WCF can pass your own custom objects?? Any help is greatly appreciated, I know on other platforms in order to Serialize your own custom object you have to do something special to your class. I wasn't sure if WCF handled this automatically or not.
EDIT
Any other help on this is still appreciated.
I have also tried adding the following to the InvoiceCharges class but was still unable to see the proxy generate correctly.
[KnownType(typeof(ListViewItem))]
Also, this is the behavior of the proxy. I am using Add Service Reference to do this.
See how it is generating several "InvoiceCharges" its all because of that ListViewItem. I can remove the DataMember attribute off of it and its fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ListViewItem 是一个 UI 概念,在您的业务或服务代码中没有任何作用。重新思考“数据”(模型),而不是用户看到的内容,并重新设计类。
您的问题涉及无法序列化。除非您想重写 UI 位以使它们对序列化更加友好,否则重新考虑模型是您最好的选择。
A ListViewItem is a UI concept and serves no purpose in your business or service code. Rethink the "data" (models) and not what the user sees and retool the class.
Your problem deals with the inability to serialize. Unless you want to rewrite UI bits to make them more serialization friendly, rethinking the model is your best bet.