Once In A White Moon - by Gina Therese Hvidsten
© 2024
Once In A White Moon

Webservice calls hangs and gets a timeout exception

Recently I encountered a problem using webservices in .Net. At irregular intervals the code suddenly threw the following exception when calling a webservice: System.Net.WebException: The operation has timed out There was nothing magical in the code around the calls to the webservice where it was handled in the usual fashion: WebserviceClass ws = new WebserviceClass(); ws.Foo(); When the code reached ws.Foo() it just waited there for over a minute before throwing the previously mentioned exception. Since using webservices is extremely streamlined and standardized in Visual Studio I initially thought the problem had to lie somewhere else than my application, like maybe there were networking issues or the ISS server that hosted the webservice had some problems. When troubleshooting all of the above and nothing panned […] Read more

Printing XPS files to a physical printer

I had the need to programatically print an XPS file, but a couple of hours of Google searches only returned examples of how to print TO an XPS file. It was extremely difficult to find how to send a XPS file to an actual physical printer. Eventually something turned up and the solution seemed to be the XpsDocument class. Look at this simplified example to see how easy it turned out to be: PrintDialog dlg = new PrintDialog(); XpsDocument xpsDoc = new XpsDocument(PATH_TO_YOUR_XPS_FILE_HERE, System.IO.FileAccess.Read); dlg.PrintDocument(xpsDoc.GetFixedDocumentSequence().DocumentPaginator, “Document title”); As you can see, reading a XPS file and then sending the contents to a printer is not very hard at all.

Change image tag generated by CKEditor

For a new project of mine I’m using a rich text editor called CKEditor. This is a highly configurable editor that, unfortunately, suffers from cluttered and not easily understandable documentation. I needed to change the generated HTML from the editor so that images that were resized not only had their size set as style attributes, but as query string variables. So I needed this: <img src=”http://yoursite.com/photo.jpg” style=”width:150px; height:200px;” /> to be output as this: <img src=”http://yoursite.com/photo.jpg?width=150&height=200″ style=”width:150px; height:200px;” /> That proved to be easier said than done, but after quite a lot of googling, asking on several forums, and getting some helpful (and some not helpful at all) replies, I finally ended up with the following: Put the following code into CKEditor’s config.js: CKEDITOR.on(‘instanceReady’, function […] Read more

Response.Redirect inside an UpdatePanel

Recently I’ve had more and more pages displaying unexpected behaviour. I had an UpdatePanel with a button inside it. The button’s Click event performed a Response.Redirect(), but nothing happened. The Javascript error console showed the following error message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. After some googling it seems that ASP.Net doesn’t quite support Response.Redirect() inside UpdatePanels any more. The solution was to make sure the button actually performed a full postback of the webpage, and not only a partial postback (as it would do because it was inside an UpdatePanel). There are two ways of doing […] Read more