Advertisements
Home > Misc > Expecting element from namespace encountered with name namespace – Error DataContractSerializer

Expecting element from namespace encountered with name namespace – Error DataContractSerializer

I have a REST  enabled WCF service with Method GetFruits() which return list of Fruit objects serialized in XML format.

My ‘Fruit’ class defined as below

   [DataContract]

public class Fruit   {

string name = string.Empty;

[DataMember]

public string Name       {

get { return name; }

set { name = value; }

}

}

I built a Client Web application and try to execute the ‘GetFruits’ and get the Fruit collection.

I got the result XML but when I try to DeSerialize XML to List<Fruit> I got below error

Reason

  • Namespace of ‘Fruit’ class at Service and Client are not matching

Fix

  • Add ‘Namespace’ tag to ‘Fruit’ class in both Client & Server.

[DataContract(Namespace = “ABC”)]

public class Fruit

{}

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: