zoukankan      html  css  js  c++  java
  • 怎么解决web service circular reference 问题


    下面是一个非常简单的例子:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    namespace WebService1
    {

        [Serializable]
        public class Person
        {
            private Person friend;
            private String name;

            public String Name
            {
                get { return name; }
                set { name = value; }
            }

            public Person Friend
            {
                get { return friend; }
                set { friend = value; }
            }
        }
    }

    using System;
    using System.Data;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.ComponentModel;

    namespace WebService1
    {
        /// <summary>
        /// Summary description for Service1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [ToolboxItem(false)]
        public class Service1 : System.Web.Services.WebService
        {

            [WebMethod]
            public Person HelloWorld()
            {
                Person him = new Person();
                Person her = new Person();

                him.Friend = her;
                her.Friend = him;
                return him;
            }
        }
    }


    运行 ASMX web service 将会得到下面的错误:

    System.InvalidOperationException: There was an error generating the XML
    document. --->
    System.InvalidOperationException: A circular reference was detected while
    serializing an object of type Person.

    IBM 网站有一篇文章描述了这个问题:
    http://www-106.ibm.com/developerwor...s-tip-j2eenet1/

    各位兄弟,谁解决过这个问题

    欢迎大家扫描下面二维码成为我的客户,为你服务和上云

  • 相关阅读:
    Chapter 1. 庞加莱群、单粒子态和时间空间反演
    QI Chapter 1
    Introduction to QFT
    在visual studio 2017中配置Qt
    BUAA软工第0次作业
    附加作业(个人)
    个人作业3——个人总结(Alpha阶段)
    单元测试
    英语学习app案例分析
    小学生四则运算改进版之
  • 原文地址:https://www.cnblogs.com/shanyou/p/456700.html
Copyright © 2011-2022 走看看