WCF学习:关于数据类(DataContract)中逻辑方法或复写方法未被初始化的原因及解决方案
2013-08-19 09:20
567 查看
在数据类(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
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 declare
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
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
ToStringmethod
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 declare
ToStringmethod
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)
- 关于JQuery中$.data绑定数据原理或逻辑
- 关于fielddata数据占用内存过大的解决方法
- 关于Jquery 异步Ajax回调函数中数据变量不能赋值给外部全局变量的原因分析及解决方法
- 关于java接收前台$.ajax格式为多维json数组数据为null的原因及解决方法
- WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer)
- [原创]WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer)
- 【应用篇】WCF学习笔记(二):ServiceContract、DataContract <第一部分>
- 关于JQuery的clone方法无法拷贝data缓存数据的问题
- Java学习之数组1(1.数组的声明;2.元素为引用数据类型的数组;3.关于main方法里的String[] args;4.数组排序;5.数3退1 数组算法,(用数组模拟链表);6数组查找之二分法;7数组的拷贝)
- wcf 基础教程 契约 Contract 数据契约DataContract序列化前身 XmlSerializer xml序列化
- 采用ISO8211封装的S57数据,中文读取时乱码及丢字原因分析与解决方法,终极解决方案.
- iOS 关于UICollectionView选中状态,当使用reloadData方法时出现数据的问题?
- 关于SET/GET PARAMETER ID的注意事项,以及取own data中数据的方法
- Android中关于JNI 的学习(二)对于JNI方法名,数据类型和方法签名的一些认识
- Silverlight Wcf 获取集合数据并绑定(DataContract,DataMember)
- Programming WCF Services 学习笔记三、Data Contract
- WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer)
- Silverlight Wcf 获取集合数据并绑定(DataContract,DataMember)