WCF学习:关于数据类(DataContract)中逻辑方法或复写方法未被初始化的原因及解决方案


   在数据类(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 declare ToString method in that class
    大致的意思是在客户端为server端Data Contract类新建部分类,在部分类中实现逻辑

    参考:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值