views:

368

answers:

1

Hi,

I have implement a small web service using .net 3.5.

I have used linq to sql classes for accessing the database.

And I have written following webmethods as follows :

using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;

...


    [WebMethod]
    public List<restaurant_detail> restaurantDetailList()
    {
        return dc.restaurant_details.ToList();
    }

Here i am using LINQ for getting data from database. Now when i am executing this webservice into my localhost i am getting following error while executing above web method :

   System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: A circular reference was detected while serializing an object of type restaurant_cuisine.
   at System.Xml.Serialization.XmlSerializationWriter.WriteStartElement(String name, String ns, Object o, Boolean writePrefixed, XmlSerializerNamespaces xmlns)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write7_restaurant_cuisine(String n, String ns, restaurant_cuisine o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write6_cuisine(String n, String ns, cuisine o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write7_restaurant_cuisine(String n, String ns, restaurant_cuisine o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write14_restaurant(String n, String ns, restaurant o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write15_restaurant_detail(String n, String ns, restaurant_detail o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write17_ArrayOfRestaurant_detail(Object o)
   at Microsoft.Xml.Serialization.GeneratedAssembly.ListOfrestaurant_detailSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
   at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
   at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
   at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
   at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
   at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
   at System.Web.Services.Protocols.WebServiceHandler.Invoke()

I this there is a problem of some serilization at the time of parsing the xml file. But i don't know how to resolve this. If anybody have the solution please provde me ASAP. Thanks in advance...

A: 

You need to change the properties of the association in your data model so that the parent property has an access modifier of Internal. That will mean the XML serialiser, which only works on public properties, won't follow the circular reference.

Phill