views:

170

answers:

2

In my webservice (WCF) i have this function

[OperationContract]
public ChooseViewData GetNcs(FilterArgument filter, int dossiersId, int usersId, 
    string token)
{        
    SessionInfo info = Tokens.CheckToken(usersId, token);
    if (info.HasError)
    {
        //return null;
    }
}

When i'm calling this function in my silverlight application, i want to know if there was an error occurred.

void client_GetNcsCompleted(object sender, GetNcsCompletedEventArgs e)
{
    if (e.Error == null)
    {

    }
}

My question is, how i can i fill the e.error? when the login is not succesful in my service, i want to throw an exception..

A: 

Hi,

For throw an exception across WCF,

You can use FaultException :

http://msdn.microsoft.com/en-us/library/ms576199.aspx

And e.Error will be fill :) Good ?

Best Regards,
Vincent BOUZON.

Vincent BOUZON
+1  A: 

This is a very common question, people ask about throwing exception from WCF to Silverlight. The answer depends on the version of Silverlight you use. Prior to Silverlight 3, catching exceptions/faults was not supported. The most elegant and generic solution for SL2 is described here: http://www.codeproject.com/KB/silverlight/SilverlightExceptions.aspx

Since Silverlight 3 was released, there is a partial support, which can be used with some tricks, as described here:

http://www.netfxharmonics.com/2009/07/Understanding-WCF-Faults-in-Silverlight-3

Boris Modylevsky