What am I doing wrong here? I'm trying to create a WCF web service that access a different dll project. The return is a custom list that contains strings and integars. When debugging I get the following error when simply navigating to Service1.svc:
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description contract: http://tempuri.org/:IService1 ----> System.Runtime.Serialization.InvalidDataContractException: Type 'RoTools.RoAmCalls+CustomItem' cannot be serialized. Consider marking it with the attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types
So researching the error online I thought adding the KnownType would help, but I'm still getting the same error. Thanks for your help. Here is the code from the Service1.cs.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace RoWebService
{
[ServiceContract]
public interface IService1
{
[OperationContract]
List<RoTools.RoAmCalls.CustomItem> SingleProductCheck(string productId);
}
[KnownType(typeof(RoTools.RoAmCalls.CustomItem))]
[DataContract]
public class CompositeType
{
List<RoTools.RoAmCalls.CustomItem> myResults;
[DataMember]
public List<RoTools.RoAmCalls.CustomItem> myResults
{
get { return myResults; }
set { myResults = value; }
}
}
And here is the code from the Service1.svc.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace RoWebService
{
public class Service1 : IService1
{
public List<RoTools.RoAmCalls.CustomItem> SingleProductCheck(string productId)
{
log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
var myReturn =
RoTools.RoAmCalls.GetPriceAndStatusSingleItem(productId, log, System.Configuration.ConfigurationManager.AppSettings["something1"],
System.Configuration.ConfigurationManager.AppSettings["something2"]);
return myReturn;
}
}
}