as you can probably make out from the question title that I am new to WCF. I have implemented this web service and one of the methods throws a custom FaultException.
namespace Feed
{
[ServiceContract]
public interface IMyClass
{
[OperationContract]
[FaultContract(typeof(CustomError))]
DataSet MyMethod(int A, int T);
}
[DataContract]
public class CustomError
{
public CustomError(string msg, int code, int id)
{
Id = id;
ErrorMessage = msg;
ErrorCode = code;
}
[DataMember]
[DataMember]
public string ErrorMessage
{
get;
set;
}
[DataMember]
public int ErrorCode
{
get;
set;
}
[DataMember]
public int Id
{
get;
set;
}
}
}
Then, I throw the proper exception in the implementation of MyMethod
namespace Feeds
{
public class MyClass : IMyClass
{
DataSet MyMethod(int A, int T)
{
try
{
//todo
DataSet ds = new DataSet();
return ds;
}
catch (Exception ex)
{
throw new FaultException<CustomError>(new CustomError("a", 1, 0));
}
}
}
}
So far so good. Now I created a simple ASP.NET website which consumes this web service. I added a WebReference in that website for the MyClass.svc web service. Problem is that when I'm trying to catch the exception: catch(FaultException ex) { } it is not able to recognize CustomError. I have done the following troubleshooting: 1. Ensure I have the wsdl updated (done numerous time, tried changing other things, everything is reflected on the client side) 2. Tried BasicHttpBinding as well as wsHttpBinding (not sure if that makes a difference) 3. Googled alot and followed sample code from MSDN religiously.
Still no luck! Am I missing something? Any suggestions will be greatly appreciated.