Tuesday, January 19, 2010

WCF errors: No set method for property on Type 'xx'

I was surprised when i first saw this error. This usually happens when you try to publish DataContract on WCF service containing Read only properties. I don't know why exactly this error occurs? As many people are concerned, workaround for this problem looks very obvious.

Add Setter to the property in question.  But, this move will defeat your original purpose of Read only property.

Huh.., Ok, here's solution. just add Private keyword to your setter method. WCF allows this provision. So, client can never see the set method on your property acting much like a read only property.

WCF errors: WCF service has zero application (non-infrastructure) endpoints.This might be because no configuration file was found on your application, or because no service element matching the service name is found in the configuration file, or because no endpoints were defined in the service element.

This WCF error always pops on my computer when ever i'm creating brand new WCF service.  Bluntly, we can understand from error that we haven't configured the service properly. Of course, there can be multiple causes. Handy tool which can help during this crisis :-) is "WCF Service Configuration Editor". You can open WCF Service Configuration Editor (SvcConfigEditor.exe) by right clicking on configuration file in your WCF service library project or accessing it under Tools menu in the Visual Studio IDE.


On left pane in editor, you'll see various service elements already defined.  Click on your Service Endpoint node.  90% of time root cause of this error will be hanging around this Service Endpoint definition. 


Remember, all the WCF service  configuration definition is found under  element


Here's the checklist that should help resolve this error.

  • Confirm your Contract attribute of Endpoint element is pointing to appropriate Service contract instead of "IService1" unless you are still using "IService1" as service contract.  
  • Confirm your Name attribute of Service Element is set appropriately to Service class implementation instead of "Service1" unless you're still using "Service1" as service implementation.
  • Also, Examine ServiceHost directive declaration in service1.svc markup.  Clean up any scrap you see and provide fully qualified namespace for the service class for service attribute.

 I strongly recommend you use Service Configuration Editor for any kind of poking around web.config/app.config related to WCF service. This way, you'll keep service configuration neat and clean. especially with complex configuration files, this tool will come handy in organizing the service elements easily.

WCF errors: Type 'xxx' is an invalid collection type since it has DataContractAttribute attribute.

If you have ever happen to get "Type xxx is an invalid collection type since it has DataContract Attribute attribute" error at any time when ever publishing WCF service, Make sure you annotate your custom collections with CollectionDataContract attribute instead of DataContract attribute. This attribute will appropriate serialize and deserialize collection.


CollectionDataContract attribute is typically utilized in scenarios involving non-WCF providers/clients to extract exact shape of data. But, you loose one important benefit with "CollectionDataContract" is "Cross Collection Interchangeability". For instance, in case of homogeneous environment of WCF client and service though WCF service exposes List collections as response, client expecting different native collection type like ArrayList/Collection can still consume the collection.


You loose this benefit if you use CollectionDataContract attribute with Collection Types.

WCF also imposes additional requirements when using collections. Keep in mind of following items when exposing custom collections via WCF service or else custom collections are not serialized/deserialized.


  • Collection should support Add method.
  • Collection should have default constructor.



Tuesday, January 5, 2010

Unity Framework v1.2 - IoC Dependency Injection

Following is the power point presentation related to IoC and Dependency Injection (DI) pattern. This presentation specifically focuses on Unity Framework v1.2 based IoC container. Integration WCF service with IoC container provides finer control over WCF instance management.