您的位置:程序门 -> .net技术 -> web services



序列化问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


序列化问题[已结贴,结贴人:pandaohua]
发表于:2007-12-20 11:16:27 楼主
webservice定义了父子类
父类
[serializable]
public   class   fatherclass
{
        private   string   id;
        public   string   id
        {
                get   {   return   id;}
                set   {   id   =   value;   }
        }
}
子类
[serializable]
public   class   childclass   :   fatherclass
{
        private   string   childname;
        public   string   childname
        {
                get   {   return   childname;   }
                set   {   childname   =   value;   }
        }
}
webservice定义
[xmlinclude(typeof(fatherclass))]
[xmlinclude(typeof(childclass))]

[webmethod]
public   fatherclasshellostus(fatherclass   obj)
{
        childclass   child   =   (childclass)obj;
        ....
        return   child;
}
这样定义发布使用就没有问题,但是采用如下的定义方式,就会出现序列化错误,请问有什么方法解决呢?
[webmethod]
public   fatherclasshellostus(fatherclass   obj)
{
        childclass   child   =   (childclass)obj;
        ....
        return   child;
}
因为程序接口中有很多子类,如果不采用xmlinclude进行声明,有什么方法可以解决这种序列化的问题呢,程序接口中,只有自定义类或对象数组类型,不存在list类型。
发表于:2007-12-20 11:37:501楼 得分:20
public       fatherclasshellostus(fatherclass       obj)  
{  
                childclass       child       =       (childclass)obj;  
                ....  
                return       child;  
}  
这样定义发布使用就没有问题,但是采用如下的定义方式,就会出现序列化错误,请问有什么方法解决呢?  
[webmethod]  
public       fatherclasshellostus(fatherclass       obj)  
{  
                childclass       child       =       (childclass)obj;  
                ....  
                return       child;  
}  
好像是一样的
发表于:2007-12-20 11:41:352楼 得分:0
不一样
webservice定义  
[xmlinclude(typeof(fatherclass))]  
[xmlinclude(typeof(childclass))]  
[webmethod]  
public       fatherclass   hellostus(fatherclass       obj)  
{  
                childclass       child       =       (childclass)obj;  
                ....  
                return       child;  
}  
这样定义发布使用就没有问题,但是采用如下的定义方式,就会出现序列化错误,请问有什么方法解决呢?  
[webmethod]  
public       fatherclass   hellostus(fatherclass       obj)  
{  
                childclass       child       =       (childclass)obj;  
                ....  
                return       child;  
}  
上面的多了
[xmlinclude(typeof(fatherclass))]  
[xmlinclude(typeof(childclass))]  
声明
发表于:2007-12-20 16:11:153楼 得分:80
加上
[xmlinclude(typeof(fatherclass))]      
[xmlinclude(typeof(childclass))]    
比较好,否则客户端可能无法解释你的自定义类


快速检索

最新资讯
热门点击