ramlicious Blogs by Tina & Prabhu

November 30, 2011

Problem with the “Specified” property when generating WCF proxy classes

Filed under: .NET,C#,Programming,WCF — Prabhuram @ 6:59 pm

I was creating WCF services today and I encountered a weird problem when generating proxy clients for the services. When creating proxy classes using SvcUtil.exe for my presentation tier, the utility creates a xxxIsSpecified property for all the value type decorated with DataMembers attributes(like int, bool, etc)

[DataContract()]
public class MyClass
{
	[DataMember()]
	public int IntMember { get; set; }
}

So in this case, the property IntMember exposes an another property called IntMemberSpecified in the proxy class. After referring at many pointers and blogs (not from MSDN), I was able to overcome this by simply setting IsRequired = true property to the DataMember() attribute. So the class should look like this after the change.

[DataContract()]
public class MyClass
{
	[DataMember(IsRequired=true)]
	public int IntMember { get; set; }
}

You will note that this problem doesn’t happen when you use the Add Service Reference from Visual Studio.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress