c# - XML Deserialization of an XDocument is too slow -


i have strange problem. have sql server database returns huge chunk of xml. in middle have .net c# code. , @ front have 2 projects, 1 wcf , other console app (for testing only).

now when run code xml db , deserialize using console app, runs pretty fast. when run same code through wcf, takes forever deserialize xml. sure, db not bottleneck here serializer is.

i using xmlserializer. cannot switch datacontractserializer because have lots of xml attributes process.

edit:

this serialization code in static class:

public static t deserialize(string xml) {     t dto = default(t);      try     {         xdocument parsedxml = xdocument.parse(xml);          xmlserializer serializer = new xmlserializer(typeof(t));          serializer.unknownattribute += new xmlattributeeventhandler(serializer_unknownattribute);         serializer.unknownelement += new xmlelementeventhandler(serializer_unknownelement);         serializer.unknownnode += new xmlnodeeventhandler(serializer_unknownnode);         serializer.unreferencedobject += new unreferencedobjecteventhandler(serializer_unreferencedobject);          if (serializer.candeserialize(parsedxml.createreader()))         {                     **--this gets stuck--**             dto = (t)serializer.deserialize(parsedxml.createreader());         }     }      catch (exception ex)     {         throw;     }      return dto; } 

then have have manager, lets workmanager uses code:

work work = serialize<work>.deserialize(xml);  

and above statement called console app , wcf project.

the interface :

[operationcontract] [webinvoke( method = "post", requestformat = webmessageformat.xml, responseformat = webmessageformat.xml, bodystyle = webmessagebodystyle.bare, uritemplate = "work")] xelement work(stream contents); 

and implementation is:

public xelement work(stream contents) {      string xml = new streamreader(contents).readtoend();       workmanager workmanager = new workmanager();      workmanager.work(xml); } 

a couple of hints:

  1. get rid of try/catch block. it's not doing you, since throw;
  2. don't call createreader twice, , use using block:

    using (var reader = parsedxml.createreader()) {     if (serializer.candeserialize(reader))     {             **--this gets stuck--**         dto = (t)serializer.deserialize(reader);     } } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -