0

I have a WCF service with one async method, updateUsers. The username is unique, so when I save changes, if exists a username that is assign to a new user, I get an UpdateException.

I Create a custom exception, UniqueKeyUsersException, that have three properties, a int64 with the ID and two strings, one for the username and other with the password. By the moment are all the fields that there are in the table of the database.

This exception, are decorate as Serializable and implements the ISerializable interface. With this, I can send the information to the client. If I do not implement this interface, to the client arrives the exception, but all the properties are null.

All works fine, to the client arrives the FaultException with the information of the username that exists.

However, I am thinking in the possibility to use only one property in the exception, of type Users, that is a self tracking entity that I have in an external library. The idea is to send to the client the entity with the register that exists in the database, so the user can decide to see the information of the existing user. In this way, the user save the needed to do a new query. If I would send the exception with my three properties, I would have to create a new object Users and convert the information from the exception to the Users entity.

My problem is that when I add in the exception a property of type Users (a STE) when I throw the FaultException, it fails, crash the service. I think that it could be for serialization reasons, that perhaps it's needed, in the implementation of the ISerialize, add the serialization of the STE.

But it would be a lot of work, because the STE has not only the information of the database, but also the tracking of the entity and other properties.

So my question is if exists any way to use a STE as property of the exception or I can only use basic types?

Thanks. Daimroc.

Álvaro García
  • 18,114
  • 30
  • 102
  • 193
  • 1
    Your STEs should already be serializable. What exception do you get when it "crash the service"? – Nick Butler May 12 '12 at 12:20
  • Well, the crash was because I have a small error in my code, now the exception arrives to the client. However, the STE is null in the client, but not when I throw the exception in the service. I have the same idea, that the STE is serializable, because I use it to transfer data between the service and the client. However, how the STE arrives as null, it makes me think that I must implement the serialization of the STE in my exception, like I do with the all other properties. But I would like to avoid that, because the STE is a bit complex because has collections and many other properties. – Álvaro García May 13 '12 at 16:38

0 Answers0