customizing VALIDATIONFAULT in WCF

May 25, 2010 at 3:45 AM

Hi Experts,

I created one Datacontract. I have put one Validation lets say SSNValidator On the following DTO
<pre>
[DataContract]
public class ClientValidDTO
   {


       [DataMember]
       public string Name
       {
           get;
           set;
       }

       [DataMember]
       [SSNValidator(false)]
       public string SSN
       {
           get;
           set;
       }</pre>

i have created one WCF service with one method ConcateClientData
which will take Client Datacontract as a Parameter.

i.e.
<pre>[ServiceContract]
[ValidationBehavior]
public interface IClientValidSrv
{
    [OperationContract]
    [FaultContract(typeof(ValidationFault))]
    ConcateDTO ConcateClientData(ClientValidDTO client);
}</pre>

At Client side when i catch exception i got ValidationResult as a fault
i.e.

<pre>
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&lt;ClientValidSrv.ValidationFault&gt; ex)
           {
               DisplayFault(ex.Detail);
           }
           catch (FaultException ex)
           {
               MessageBox.Show(ex.Message);
           }
           finally
           {
               proxyClient.Close();
           }

       }

        private static void DisplayFault(ClientValidSrv.ValidationFault faults)
       {
          MessageBox.Show(&quot;Fault Occured:&quot;);
           foreach (ClientValidSrv.ValidationDetail validationResult in faults.Details)
           {
             MessageBox.Show(string.Format(&quot;Message={0} Key={1} Tag={2}&quot;, validationResult.Message, validationResult.Key, validationResult.Tag));

           }
       }</pre>


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?