public WcfResponse Create(CriteriaRequest request)
        {
            var result = new WcfResponse();

            try
            {
                request = ConvertRequest(request);

                // unpack criteria data into object
                object criteria = GetCriteria(request.CriteriaData);
                if (criteria is PrimitiveCriteria)
                {
                    criteria = ((PrimitiveCriteria)criteria).Value;
                }

                SilverlightRequestProcessor processor     = new SilverlightRequestProcessor();
                SilverlightCriteriaRequest  createRequest = new SilverlightCriteriaRequest(
                    request.TypeName,
                    criteria,
                    (IPrincipal)MobileFormatter.Deserialize(request.Principal),
                    (ContextDictionary)MobileFormatter.Deserialize(request.GlobalContext),
                    (ContextDictionary)MobileFormatter.Deserialize(request.ClientContext));

                SilverlightResponse createResponse = processor.Create(createRequest);
                if (createResponse.Error != null)
                {
                    result.ErrorData = new WcfErrorInfo(createResponse.Error);
                }
                result.GlobalContext = MobileFormatter.Serialize(createResponse.GlobalContext);
                result.ObjectData    = MobileFormatter.Serialize(createResponse.Object);
            }
            catch (Exception ex)
            {
                result.ErrorData = new WcfErrorInfo(ex);
            }
            finally
            {
                SilverlightRequestProcessor.ClearContext();
            }
            return(ConvertResponse(result));
        }
 /// <summary>
 /// Override to convert the request data before it
 /// is transferred over the network.
 /// </summary>
 /// <param name="request">Request object.</param>
 protected virtual CriteriaRequest ConvertRequest(CriteriaRequest request)
 {
     return(request);
 }