I'm working on a WCF service.
One of the OperationContracts requres a complex type as one of the parameters (System.Exception to be specific).
When the client calls the proxy if I create a new exception, eg.
System.Exception toNewException = new Exception();
And send it... it works rather nicely.
But if i try to send an exception of type 'System.Web.HttpUnhandledException'. The service faults with an unknown type. (see error below)
There was an error while trying to serialize parameter http://tempuri.org/:Exception. The InnerException message was 'Type 'System.Web.HttpUnhandledException' with data contract name 'HttpUnhandledException:http://schemas.datacontract.org/2004/07/System.Web' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
I've researched the known types attribute... but I have not found any examples or documentation so far that has helped.
Anyone know a good source for information on how I may be able to alter my client/server to accept/work with any kind of exception?
To make my question a little bit more detailed... The error states; 'Add any types not known statically to th elist of known types'. That is what I want to know how to do specifically for a complex .net object like system.exception.
Update
I tried making the following changes:
[OperationContract]
[ServiceKnownType(typeof(HttpUnhandledException))]
void LogError(Exception Exception, Boolean LogInternalFlag, int UserId, int ApplicationId, int SeverityId);
and I ended up getting another error!
There was an error while trying to serialize parameter http://tempuri.org/:Exception. The InnerException message was 'Type 'System.Collections.ListDictionaryInternal' with data contract name 'ArrayOfKeyValueOfanyTypeanyType:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
Atleast the error with the exception made sense... I'm not sure what this means at all.
I'm also going to throw in that I did try to serialize the exception as xml and passing it as a string... unfortunately thats not as simple as it may sound, and there are to many considerations to take into account for the serialization of the exception and any inner exceptions.