c# - Performance problems for WCF Services on Windows Phone 8 -


i'm going make windows phone 8 app gets data wcf services. i'm starting wp 8 development , i'm begging wonder if wcf best choice. after wsdl services send lot of xml data , formatting every response not best thing phone app. question is: ok use wcf big xml responses or should try else, maybe httphandlers return json data maybe dynamic gzip responses? not sure if work wp8, said i'm wondering right direction point self to.

thanks help. decided go wcf , json responses connect windows phone 8 app.. didn't choose wcf kind of part of assignment, going use build in authentication , authorization system of wcf user credentials.. i'm going serialize response every time in json format , gzip when returning it. modest testing turns out quiet fast. if else wondering here sample code (i'm using json.net):

private string getsupplierslite()     {         // objectcontext data source service.         northwindentities context = this.currentdatasource;          try         {             var suppliers = (from s in context.suppliers                              select new                              {                                  address = s.address,                                  city = s.city,                                  companyname = s.company_name,                                  contactname = s.contact_name,                                  contacttitle = s.contact_title,                                  country = s.country,                                  fax = s.fax,                                  phone = s.phone,                                  postalcode = s.postal_code,                                  region = s.region,                                  supplierid = s.supplier_id,                              }                             ).tolist();              string jsonclient = null;             jsonserializer jsonserializer = new jsonserializer();             jsonserializer.nullvaluehandling = nullvaluehandling.ignore;             jsonserializer.missingmemberhandling = missingmemberhandling.error;             jsonserializer.referenceloophandling = referenceloophandling.error;             try             {                 using (stringwriter sw = new stringwriter())                 {                     using (jsontextwriter jtw = new jsontextwriter(sw))                     {                         jsonserializer.serialize(jtw, suppliers);                     }                     jsonclient = sw.tostring();                 }             }             catch (exception ex)             {                 ex = ex; // have breakpoint here can inspect exception             }             return jsonclient;         }         catch (exception ex)         {             throw new applicationexception(string.format(                 "an error occurred: {0}", ex.message));         }     }      [webget]     public string getsupplierslitezip()     {         return zip(getsupplierslite());     }      private string zip(string value)     {         //transform string byte[]           byte[] bytearray = new byte[value.length];         int indexba = 0;         foreach (char item in value.tochararray())         {             bytearray[indexba++] = (byte)item;         }          //prepare compress         system.io.memorystream ms = new system.io.memorystream();         system.io.compression.gzipstream sw = new system.io.compression.gzipstream(ms, system.io.compression.compressionmode.compress);          //compress         sw.write(bytearray, 0, bytearray.length);         //close, not flush cause bytes go missing...         sw.close();          //transform byte[] zip data string         bytearray = ms.toarray();         system.text.stringbuilder sb = new system.text.stringbuilder(bytearray.length);         foreach (byte item in bytearray)         {             sb.append((char)item);         }         ms.close();         sw.dispose();         ms.dispose();         return sb.tostring();     } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -