Friday, March 16, 2012

Method Overloading error in WCF

In normal behavior of  WCF if you try to implement method overloading in WCF service contract it will throw the an InvaildOperationException once you invoke the service.

[OperationContract]
[FaultContract(typeof (ServiceException))]
BasicDataDTO[] RetrieveGenericData(EBasicDataType genericType, string descriptionPart);

[OperationContract]
[FaultContract(typeof (ServiceException))]
BasicDataDTO[] RetrieveGenericData(string styleNo, int versionId, EBasicDataType genericType, string descriptionPart);
In generally above statement will throw the InvaildOperationException.To overcome this problem you have to put OperationContractAttribute with Name Property.
[OperationContract(Name = "GetGenericData")]
[FaultContract(typeof (ServiceException))]
BasicDataDTO[] RetrieveGenericData(EBasicDataType genericType, string descriptionPart);

[OperationContract(Name = "GetAllgenericData")]
[FaultContract(typeof (ServiceException))]
BasicDataDTO[] RetrieveGenericData(string styleNo, int versionId, EBasicDataType genericType, string descriptionPart);
In Object Oriented aspect above code is correct ,WCF always generate proxy using the WSDL.The problem is WSDL does not support the concepts like inheritance and overloading.

No comments:

Post a Comment