Hi Experts,
I created one Datacontract. I have put one Validation lets say SSNValidator On the following DTO
[DataContract]
public class ClientValidDTO
{
[DataMember]
public string Name
{
get;
set;
}
[DataMember]
[SSNValidator(false)]
public string SSN
{
get;
set;
}
i have created one WCF service with one method ConcateClientData
which will take Client Datacontract as a Parameter.
i.e.
[ServiceContract]
[ValidationBehavior]
public interface IClientValidSrv
{
[OperationContract]
[FaultContract(typeof(ValidationFault))]
ConcateDTO ConcateClientData(ClientValidDTO client);
}
At Client side when i catch exception i got ValidationResult as a fault
i.e.
private void btnSave_Click(object sender, EventArgs e)
{
ClientValidSrv.ClientValidSrvClient proxyClient = new PresentationLayer.ClientValidSrv.ClientValidSrvClient();
try
{
ClientValidSrv.ClientValidDTO objClientDTO = new ClientValidSrv.ClientValidDTO();
objClientDTO.Name = txtName.Text;
objClientDTO.SSN = txtSSN.Text;
objClientDTO.State = txtState.Text;
ClientValidSrv.ConcateDTO objContateDTO = proxyClient.ConcateClientData(objClientDTO);
label3.Text = objContateDTO.FullName;
}
catch (FaultException<ClientValidSrv.ValidationFault> ex)
{
DisplayFault(ex.Detail);
}
catch (FaultException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
proxyClient.Close();
}
}
private static void DisplayFault(ClientValidSrv.ValidationFault faults)
{
MessageBox.Show("Fault Occured:");
foreach (ClientValidSrv.ValidationDetail validationResult in faults.Details)
{
MessageBox.Show(string.Format("Message={0} Key={1} Tag={2}", validationResult.Message, validationResult.Key, validationResult.Tag));
}
}
ValidationResult has Message,Key,Tag as default properties.
How can i add additional property ErrorId in validationResult to show customize error message at client side?