下边是一个万分不难的事例:
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/

诸君兄弟,哪个人解决过那几个标题

相关文章

网站地图xml地图