More in this section

Forums / Developing with Sitefinity / Problem invoking web service

Problem invoking web service

2 posts, 0 answered
  1. Tim
    Tim avatar
    7 posts
    Registered:
    13 Aug 2009
    21 Sep 2009
    Link to this post

    I have installed the Contacts Service Pluggable Module example and everything appears to be functioning fine except for the Web Service. (I am using Sitefinity 3.7)

    I am attempting to invoke the web service through the browser( http://localhost/MySitefinitySite/Sitefinity/Admin/Services/contactsservice.asmx) and it does not seem to be working...

    When I invoke with a parameter that returns 0 rows it seems to work....

    <?xml version="1.0" encoding="utf-8" ?>

    - <GridBindingData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
      <Count>0</Count>
      <Data />
      </GridBindingData>

    however when I invoke with a parameter that should return a result I receive...

    System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Sample.Contacts.SimpleContactItem cannot be serialized because it does not have a parameterless constructor.
    at System.Xml.Serialization.TypeDesc.CheckSupported()
    at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
    at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type type)
    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.Write2_GridBindingData(String n, String ns, GridBindingData o, Boolean isNullable, Boolean needType)
    at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_GridBindingData(Object o)
    at Microsoft.Xml.Serialization.GeneratedAssembly.GridBindingDataSerializer.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()


    If I create a parameterless constructor of SimpleContactItem I then receive the following error...

    System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type Sample.Contacts.SimpleContactItem was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
       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.Write2_GridBindingData(String n, String ns, GridBindingData o, Boolean isNullable, Boolean needType)
       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_GridBindingData(Object o)
       at Microsoft.Xml.Serialization.GeneratedAssembly.GridBindingDataSerializer.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()
    


    How can I get this web service example working?

    Thanks,

    Tim
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    24 Sep 2009
    Link to this post
    Hello Tim,

    You have several options. The first one, is to add a parameterless constructor
    namespace Sample.Contacts.Services 
        /// <summary> 
        /// Provides web service methods for Contacts module. 
        /// </summary> 
        [ScriptService] 
        public class ContactsService 
        { 
            public ContactsService 
            { 
                //what do you want this service to do, when requested 
                //through a browser? 
            } 

    How do you invoke the service with a parameter?

    You can also try the following - Since the Contacts module is based on the Generic Content, what you can do it so use the ContentService.asmx. Just initialize it with the Contacts provider and see what methods could work for you.

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered