Welsh-Wizard

I am trying to throw back a generic fault to my client app using the FaultException, however each time the fault is returned to the client it is always of type 'unknownfault'

Here are a few snippets of my code (using tcp protocol)

Interface....

[ServiceContract()]
interface IWcfDocumentManager
{
[FaultContract(typeof(MyErrorFault))]
byte[] Document(DocumentData documentData, int pageId, bool encrypt)
}

Generic fault

[DataContract()]
public class MyErrorFault
{
private string report;

public MyErrorFault(string message)
{
this.report = message;
}

[DataMember]
public string Message
{
get { return this.report; }
set { this.report = value; }
}

}

I throw the fault in this way

throw new FaultException<MyErrorFault>(new MyErrorFault("Test fault"), new FaultReason("test reason"));

and in the client i catch the fault using this method..

catch (TimeoutException timeProblem)
{
Console.WriteLine("The service operation timed out. " + timeProblem.Message);
Console.ReadLine();
}
catch (FaultException<MyErrorFault> fault)
{
Console.WriteLine(fault.Detail.Message);
Console.ReadLine();
}
catch (FaultException unknownFault)
{
Console.WriteLine("An unknown exception was received. " + unknownFault.Message);
Console.ReadLine();
}
catch (CommunicationException commProblem)
{
Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace);
Console.ReadLine();
}

But it always jumps into the highlighted part of the errorhandler. Any help would be much appreciated.


Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Brian McNamara - MSFT

Hmmm. It looks like you are doing things properly. What is the value of unknownFault.Message that you get back (Is is the 'test reason', or something else )






Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Welsh-Wizard

yes the value of the message property is 'test reason' also the value of the action property on the unknown fault is

http://tempuri.org/IWcfDocumentManager/GetDocumentBytesWcfMyErrorFaultFault

which also looks correct!

The only other thing i can think off is that the FaultException is raised from a windows workflow, could this be the problem




Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Brian McNamara - MSFT

What is the value of unknownFault.GetType()

How was the client created svcutil/Add ServiceReference Or by hand (shared contract assembly)






Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Welsh-Wizard

The value is 'System.ServiceModel.FaultException'

The client was created by hand




Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Brian McNamara - MSFT

Hmmm...

The hand-authored client is using the same contract (marked up with the same FaultContract), yes

Is the client part of the same application, or a separate application (either running on the same box or a different box)






Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Welsh-Wizard

yes it uses the same contract on the client. The client is a separate application (a console test app) which is running on the same box as the windows service hosted wcf class.




Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Brian McNamara - MSFT

What binding are you using

Tell me more about the workflow... if it is easy to do, can you see if it repros when the workflow is not in the picture






Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Welsh-Wizard

its using tcp binding

I'll try and remove the workflow part and see if it is that that is causing the issue




Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Welsh-Wizard

Ok ive had some success by regenerating the client contract using the tools and not by hand, and it now is catching the correct generic error. However all the properties of the the class on the client are empty Any ideas

These are my classes...
Code Snippet



//Simple error class

[DataContract]
public class WcfFaultException
{
[DataMember]
public string errorcode;
[DataMember]
public string message;
[DataMember]
public string details;
[DataMember]
public Guid wf_instance;
}



//Client side

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute()]
public partial class WcfFaultException : object,System.Runtime.Serialization.IExtensibleDataObject
{

private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

private string messageField;
private string errorcodeField;
private string detailsField;
private Guid wf_instanceField;

public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public string message
{
get
{
return this.messageField;
}
set
{
this.messageField = value;
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public string errorcode
{
get
{
return this.errorcodeField;
}
set
{
this.errorcodeField = value;
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public string details
{
get
{
return this.detailsField;
}
set
{
this.detailsField = value;
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public Guid wf_instance
{
get
{
return this.wf_instanceField;
}
set
{
this.wf_instanceField = value;
}
}
}






Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Brian McNamara - MSFT

It seems like you have switched ServiceContract/FaultContract/DataContract since your original post... can you share the new ServiceContract/FaultContract, as well as the line of code that throws

And you are saying that now the client receives the correct exception type, but the data in that exception is un-populated






Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Welsh-Wizard

Here is the service contract

Code Snippet

[ServiceContract()]

interface IWcfDocumentManager
{

[OperationContract(Name = "GetDocumentBytes")]
[FaultContract(typeof(WcfFaultException))]
byte[] Document(DocumentData documentData, int pageId, bool encrypt, bool burnAnnotations);
}


//This is the line of code to throw the error


WcfFaultException() _faultex = new WcfFaultException();
_faultex.message = e.Exception.Message;
_faultex.details = e.Exception.StackTrace;

throw new FaultException<WcfFaultException>(_faultex, _faultex.message,
new FaultCode(_faultex.errorcode));


Yep thats right, the client now receives the right error, but all the poperties of the WcfFaultException class on the client side are not populated. If i drill down through the object i can see the resultant errors under ExtensionData




Re: Windows Communication Foundation (Indigo) FaultException always returns unknownfault type on client

Brian McNamara - MSFT

I believe this was resolved here

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1662183&SiteID=1