Click here to Skip to main content
15,070,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I wrote a WCF Rest service to consume some service contracts from Xamarin Forms application.

I used Repository design pattern and unit of work for database transactions in DAL.

Then I wrote a class MobileResult to collectivize my returned objects.

But somehow it doesn't work.

Can you help me with this issue.

Thanks.

What I have tried:

I wrote a Operation Contract like this;

C#
[OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetWorkCommandsInProduction")]
        MobileResult GetAllWorkCommandsInProduction();


I wrote my MobileResult like this;

C#
[DataContract]
   public class MobileResult
   {
       [DataMember]
       public bool result { get; set; }
       [DataMember]
       public object data { get; set; }

       public MobileResult(bool res, object obj)
       {
           result = res;
           data = obj;
       }
   }


And finally this is where I return MobileResult;

C#
public MobileResult GetAllWorkCommandsInProduction()
        {
            UnitOfWork work = new UnitOfWork(new BILPLASDatabaseContext());

            var products = work.Repository<WorkCommandProductions>().GetAll();

            // In here my 'products' is filled(there is no problem with this)
            // But I get 'System.Runtime.Serialization.SerializationException' in 
            // System.Runtime.Serialization.dll
            // I tried to return only one 'product' object but I get same error again.
            // When I return only one property of one 'product' object(ex. 
            // products[0].ID) then it returns without exception.  
            return new MobileResult(true, products);
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900