archana mistry

archana mistry

  • NA
  • 1
  • 5.4k

Getting Error System.InvalidOperationException When Invoke WebService Method

Jan 27 2012 7:23 AM
I had Create One WebService..and Create Get Method inside WebService..
My code is

public class WebService : System.Web.Services.WebService {
    DataClassesDataContext db = new DataClassesDataContext();

   
public WebService ()
   
{
       
//Console.log("Enter");
       
//Uncomment the following line if using designed components
       
//InitializeComponent();
   
}

   
[WebMethod]
   
public string HelloWorld() {
       
return "Hello World";
   
}

   
[WebMethod]
   
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
   
public object Get()
   
{        
       
return db.Countries.ToList();
   
}
}
But When I am Test Web-service at that I am getting following Error..


System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Collections.Generic.List`1[[Country, App_Code.hlnie2jd, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] may not be used in this context. at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_anyType(Object o) at Microsoft.Xml.Serialization.GeneratedAssembly.ObjectSerializer.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()

any one having solution please help me

Archana Mistry
Sr. Programmer
Kintudesigns.com


Answers (2)