Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XMLSerializer and WCF in a Windows Service gives OutOfMemoryExceptions

Posted on 2010-09-15
6
Medium Priority
?
1,621 Views
Last Modified: 2012-06-21
In our application we are currently noticing that once a while our Windows Services generates an OutOfMemoryException on one of our WCF services. We have digged into the code and found out that WCF is in our case using a specific constructor from the XmlSerializer which causes an Assembly leak (Sort of Memory leak).

What this XmlSerializer does, is that it generates dynamic assemblies from  the schema's so that it can serialize and deserialize all the sent and received data according to the contract. This assembly is then attached to the AppDomain in which the Windows Service is running, but then never gets cleaned because the garbage collector won't do it. Everytime a WCF call is made a new XmlSerializer gets instantiated which causes the amount of generated assemblies to add slowly with in the end an OutOfMemoryException as the result.

The solutions we tried (and failed):
Using a static XmlSerializer: This works, it will generate only a few dynamic assemblies once, so you won't run into the OutOfMemoryException. However we can't simply inject this XmlSerializer into WCF so it can use our Serializer. It keeps generating new ones. Help on how to inject our static XmlSerializer in a dynamic way into WCF would be great.
Not use WCF: This is not an option. We are bound to WCF and we are not allowed to change it to WebRequest or something else.
Change the types: We tried to change the type to XmlElement, but for some reason the XmlSerializer tries to (de)serialize the received Xml to a XmlElement while this is not necesarry. The result is still a OutOfMemoryException.
Restarting service daily: We can not simply restart the windows service daily. This will interrupt processing too much.

We searched the web quite extensively and how the XmlSerializer works is according to MS-design, but I don't see any references to people who use it in combination with WCF and a Windows Service.

Any thoughts?
0
Comment
Question by:existenz2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 33690659
One more option would be to break up the service into multiple services.  That way each service would be handling less assemblies.
0
 
LVL 14

Author Comment

by:existenz2
ID: 33698656
Would be possible, but then we still would run into a OOM-exception. I'm probably also not getting approval for such an architecural change, but it's definatly a direction I didn't look at yet so I'll give it a shot.

Anybody else with some thoughts?
0
 
LVL 14

Author Comment

by:existenz2
ID: 33714270
The multiple services option was indeed sadly not viable, because of our architectural constraints. Hopefully anybody else has some ideas left :)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 21

Accepted Solution

by:
MogalManic earned 1500 total points
ID: 33715224
Can you describe the Web Service in more detail?  How many methods?  How many assemblies? (is it possible to send sample code?[not sure if it would help])


How about converting the Windows Service to an IIS service.  With IIS you can assign multiple worker processes to the application and you can automatically recycle the worker processes.
0
 
LVL 14

Author Comment

by:existenz2
ID: 33715532
It's 4 methods in 1 assembly that are causing the problems. Sample code is not possible due to security restrictions. Converting it to a IIS services is neither allowed due to architectural constraints, so I'm pretty stuck in the corner of Windows Services.

One idea:
I could configure the Recovery settings to restart the application when it goes OOM. That would give us some kind of recycling of the worker processes in which the memory gets cleaned. It's not nice and definatly not the best way to do it, but it will probably work.
0
 
LVL 14

Author Closing Comment

by:existenz2
ID: 33723199
Thanks for the help. We managed to come up with a working solution inside WCF.

In the end it was pretty easy.

Awarding points for the help/thoughts which steered us in this direction.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question