I have a theoretical question. I have a WCF web service that need to talk with .NET clients and an iPhone application.
In the service I have many methods like:
User Login(string email,string password); etc..
If successful, I want the service to return me the User. Otherwise, I want the service to throw me an custom exception such as EmailNotFoundException or PasswordNotCorrectException.
I have been told it’s not the best way to do so, especially because iPhone clients will use this service.
Should I change all my methods to return some WrapperEntity that will contain Object and error string/Exception object?
This is important for me, because sometimes I need to know why the operation fails. If Login returns null I will know the operation failed but I won’t know why.
You should not use exceptions in a WCF service to regularly communicate with a consumer of your service. Instead, look at creating a response object that contains everything you would need to know about the operation.
Something like:
and then your Login operation would look something like:
This way, if the operation fails, you can put a message in the response that explains why.