I honestly have no clue why I don't get the "InnerException" or rather DetailMessage our of an FaultException and I have no clue why. The error does appear in the XML-Response, but for whatever reason it's not available when I access the exception.
ServiceFault-class:
public partial class ServiceFault : object, System.ComponentModel.INotifyPropertyChanged {
private string causeMessageField;
private int errorCodeField;
private bool errorCodeFieldSpecified;
private MessageEvent[] listField;
private string messageField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string causeMessage {
get {
return this.causeMessageField;
}
set {
this.causeMessageField = value;
this.RaisePropertyChanged("causeMessage");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public int errorCode {
get {
return this.errorCodeField;
}
set {
this.errorCodeField = value;
this.RaisePropertyChanged("errorCode");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool errorCodeSpecified {
get {
return this.errorCodeFieldSpecified;
}
set {
this.errorCodeFieldSpecified = value;
this.RaisePropertyChanged("errorCodeSpecified");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
[System.Xml.Serialization.XmlArrayItemAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public MessageEvent[] list {
get {
return this.listField;
}
set {
this.listField = value;
this.RaisePropertyChanged("list");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
public string message {
get {
return this.messageField;
}
set {
this.messageField = value;
this.RaisePropertyChanged("message");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
Code to catch and process ServiceFault:
public static string GetFaultExceptionMessages(FaultException<ServiceFault> e)
{
var msgs = "";
foreach (var error in e.Detail.list)
{
msgs += error.DetailMessage.ToString() + Environment.NewLine;
}
return msgs;
}
Response:
<env:Envelope xmlns:env='http://www.w3.org/2003/05/soap-envelope'><env:Header></env:Header>
<env:Body>
<env:Fault xmlns:env='http://www.w3.org/2003/05/soap-envelope'>
<env:Code xmlns:env='http://www.w3.org/2003/05/soap-envelope'>
<env:Value xmlns:env='http://www.w3.org/2003/05/soap-envelope'>env:Receiver</env:Value>
</env:Code>
<env:Reason xmlns:env='http://www.w3.org/2003/05/soap-envelope'>
<env:Text xml:lang='de-DE' xmlns:env='http://www.w3.org/2003/05/soap-envelope'>Fachlicher Fehler:</env:Text>
</env:Reason>
<env:Detail xmlns:env='http://www.w3.org/2003/05/soap-envelope'>
<ns2:ServiceFault xmlns:ns2='xxxx>
<errorCode>0</errorCode>
<list>
<MessageEvent>
<MessageInstanceId>-9223372036854775587</MessageInstanceId>
<MessageCode>CRM9007</MessageCode>
<ShortMessage>Loser Kontakt angelegt</ShortMessage>
<DetailMessage>Es wurde ein loser Kontakt angelegt, weil kein Partner identifiziert werden konnte.</DetailMessage>
<SeverityType>Warn</SeverityType>
</MessageEvent>
</list>
<message>Fachlicher Fehler:</message>
</ns2:ServiceFault>
</env:Detail>
</env:Fault>
</env:Body>
</env:Envelope>
The only Thing that makes it into my application is the MessageInstanceId. Everything else is, for whatever reason, null. Can somebody please tell me what I'm doing wrong?