How to solve the Web Service circular reference Problem

Source: Internet
Author: User

The following is a simple example:
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;
}
}
}

When you run asmx web service, the following error is returned:

System. invalidoperationexception: There was an error generating the XML
Document. --->
System. invalidoperationexception: A circular reference was detected while
Serializing an object of type person.

There is an article on the IBM websiteArticleDescribes the problem:
Http://www-106.ibm.com/developerwor...s-tip-j2eenet1/

Who have solved this problem?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.