WCF学习:关于数据类(DataContract)中逻辑方法或复写方法未被初始化的原因及解决方案
来源:互联网 发布:软件设计方案及要求 编辑:程序博客网 时间:2024/06/05 04:54
在数据类(DataContract)中添加逻辑方法或复写如ToString()方法,WCF都不会对这些方法进行初始化,原因在于:
Data contract is for transporting data - not for transporting logic. When you use add service reference, add web reference, xsd.exe, wsdl.exe or svcutil.exe only properties are described - all your methods declared on server are lost
(Data Contract类是传输数据 - 而不是传输逻辑。在使用“添加服务引用”,“添加WEB引用”,xsd.exe,wsdl.exe或者svcutil.exe,只会描述属性 - server端所有的方法定义都会丢失(即不做初始化)
解决方案:
- The ugly way: share the library with data contract between service and client instead of creating a new type on the client through one of the mentioned tools
- Those tools should create partial classes. Your
ToString
method obviously belongs to the client side because it is related to data presentation so create second partial part of the contract class on the client and declareToString
method in that class
大致的意思是在客户端为server端Data Contract类新建部分类,在部分类中实现逻辑
参考:
http://stackoverflow.com/questions/10401186/tostring-method-overriding-in-datacontract-in-wcf
http://stackoverflow.com/questions/1181039/wcf-datacontract-tostring-function
- WCF学习:关于数据类(DataContract)中逻辑方法或复写方法未被初始化的原因及解决方案
- WCF中 DataContract、DataMember的作用
- 关于在类中复写hashCode方法的返回值问题
- 关于在Fragment中使用startActivityForResult();方法后onActivityResult()未被调用的解决方案
- 关于C++中定义对象及对象初始化的方法
- WCF数据契约(DataContract)
- Java中复写equals()方法的同时也要复写hashCode()方法
- 数据标准化的原因及方法
- 数据标准化的原因及方法
- 【OC学习-14】多态是什么?看父类方法在子类中复写产生的效果
- 关于Hibernate QBC语句逻辑或(or)的查询方法
- 复写的Object常用方法
- 18天Java学习---13.面向对象编程08-Java中继承的概念,子类实例化过程,super()及方法复写
- 在Activity的onCreate方法中显示PopupWindow导致异常的原因分析及解决方案
- 在Activity的onCreate方法中显示PopupWindow导致异常的原因分析及解决方案
- 在Activity的onCreate方法中显示PopupWindow导致异常的原因分析及解决方案
- 在Activity的onCreate方法中显示PopupWindow导致异常的原因分析及解决方案
- 判断类未初始化数据但不为空的方法
- hdu4435 charge-station
- Tour(hdu 3488,KM+拆点)
- android中进行https连接的方式
- 在windows2003上部署apache+PHP遇到的部分问题(附IIS配置FastCGI驱动PHP方法)
- 极限优化:Haar特征的另一种的快速计算方法—boxfilter
- WCF学习:关于数据类(DataContract)中逻辑方法或复写方法未被初始化的原因及解决方案
- Sorting Slides(poj1486,绝对匹配边)
- 机器学习经典算法8-树回归
- C++ STRING 和WSTRING 之间的互相转换函数
- 地面储藏室而成这样
- SQL预处理句
- 解决Eclipse中文乱码
- Java JFrame实现无边框无标题
- 《Hadoop实战(第2版)》迷你书