Wednesday, February 29, 2012

WSE: Server unavailable, please try later

This is an amazing gotcha that had me almost throw my computer off the sixth floor of my building. First to narrow down the steps I took in order to determine what was actually wrong:
  1. I regenerated my WSDL file
  2. I rebuilt my projects
  3. I closed visual studio and open it again
Unfortunately none of those things worked this time to fix the most useless WSE Exception of all time "Server unavailable, please try later"

It was later pointed out to me that I made a big mistake when putting together a public property in one of my classes that would be serialized by WSE for the WSDL definition. I was throwing an exception in the setter of my property. I did this on purpose because I didn't want anyone to use the setter. 

Well then why not just don't include the setter?
Ah, you see, if it were that simple then WSE wouldn't have been replaced by WCF and everyone would still be using it. WSE is pretty terrible for the record, but it is pre-WCF. The reason I didn't just exclude the setter is because WSE requires that all properties include getters and setters otherwise they will not be included - period.

The Mind Numbing Bug
Since I had both a getter and a setter - that part was okay - however I did have an exception being explicitly thrown in the setter so the client side would try to set the setter and it would throw an exception. The sad part is the exception that is returned is a silly WSE SoapException that simply says: "Server unavailable, please try later" - which is incredibly useless...

So here are the guidelines to using properties with WSE:
  1. Properties are not allowed to be Read Only if you want to use them.
  2. You are not smarter than WSE - if you are not going to use a setter or a getter then use a default of some kind - but do not throw any exceptions.
  3. If you want to hide a property from yourself in visual studio use the "System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)" attribute as highlighted here.
Why are you still using WSE? Didn't you know it is obsolete?
Yes, yes I know it is obsolete. It is not my decision to change the technology being used at my work place. I can make a plan for change and implement it slowly, but that is about it. So I am using it because it is part of a legacy system I am working on. Trust me I would rather be using WCF.

No comments:

Post a Comment