WCF - Serialization Exception even after giving DataContract and DataMember
Posted
by Lijo
on Stack Overflow
See other posts from Stack Overflow
or by Lijo
Published on 2010-06-05T15:43:18Z
Indexed on
2010/06/05
15:52 UTC
Read the original article
Hit count: 477
wcfserviceclient
Hi Team,
I am getting the following exception eventhough I have specified the Datacontract and Datamember. Could you please help me to understand what the issue is?
"Type 'MyServiceLibrary.CompanyLogo' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute."
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Runtime.Serialization;
using MyServiceLibrary;
namespace MySelfHostConsoleApp
{
class Program
{
static void Main(string[] args)
{
System.ServiceModel.ServiceHost myHost = new ServiceHost(typeof(NameDecorator));
myHost.Open();
Console.ReadLine();
}
}
}
//The Service is
using System.ServiceModel;
using System.Runtime.Serialization;
namespace MyServiceLibrary
{
[ServiceContract(Namespace = "http://Lijo.Samples")]
public interface IElementaryService
{
[OperationContract]
CompanyLogo GetLogo();
}
public class NameDecorator : IElementaryService
{
public CompanyLogo GetLogo()
{
Shape cirlce = new Shape();
CompanyLogo logo = new CompanyLogo(cirlce);
return logo;
}
}
[DataContract]
public class Shape
{
public string SelfExplain()
{
return "sample";
}
}
[DataContract]
public class CompanyLogo
{
private Shape m_shapeOfLogo;
[DataMember]
public Shape ShapeOfLogo
{
get
{
return m_shapeOfLogo;
}
set
{
m_shapeOfLogo = value;
}
}
public CompanyLogo(Shape shape)
{
m_shapeOfLogo = shape;
}
}
}
//And the host config is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyServiceLibrary.NameDecorator"
behaviorConfiguration="WeatherServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8017/ServiceModelSamples/FreeServiceWorld"/>
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="MyServiceLibrary.IElementaryService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WeatherServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Thanks
Lijo
© Stack Overflow or respective owner