I'm trying to throw a custom exception from a WCF Service to a Client application. I will try to describe as much code as I can think can be related to this.
Exception:
using System.Runtime.Serialization;
namespace App.Exceptions
{
/// <summary>
/// General App exception
/// </summary>
[DataContract]
public class AppException : System.Exception
{
private string strMessage = "An unknown exception occurred";
/// <summary>
/// Creates a new instance of a App Exception
/// </summary>
public AppException()
{ }
/// <summary>
/// Creates a new instance of a App Exception
/// </summary>
/// <param name="Message">Message to send as exception</param>
public AppException(string Message)
{ strMessage = Message; }
public override string Message
{ get { return strMessage; } }
}
}
Service code:
(...)
using App.Exceptions;
namespace App.Services
{
public class Service1 : IService1
{
public Service1 ()
{ }
public void TestFunction()
{
throw new AppException();
}
}
}
ServiceInterface:
(...)
namespace App.Services.Interfaces
{
[ServiceContract]
public interface IService1
{
[OperationContract]
void TestFunction();
}
}
Client:
(...)
using App.Exceptions;
(...)
try
{
service.TestFunction();
}
catch (AppException ex)
{
}
Everything works very well, function is called on the service and exception is thrown. References are exactly the same either on Client and Server. I've cheched and AppException
is being referenced on the same namepsace so it should be ok.
I've tried on service app.config
to set <serviceDebug includeExceptionDetailInFaults="True" />
and also setting it to False just to see if I get a different Exception and in fact it is different so I'm not really understanding why the break point set on the catch for the AppException
is never hit.
EDIT:
Service config:
<service name="App.Services.Service1">
<endpoint address="" binding="basicHttpBinding" contract="App.Services.Interfaces.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/App.Services/Service1/" />
</baseAddresses>
</host>
</service>
Client config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/App.Services/Service1/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="Services.IService1" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>