Our build server wasn’t producing the same results as our local development machines. The same C# code yielded two different sets of code libraries. After much head-banging and hand-wringing, we finally traced the problem to an obscure error in the way Visual Studio 2008 handles .csproj files.
Basically, the Visual Studio IDE doesn’t handle the CopyLocal setting properly. This post from paraesthesia set us on the right track.
I have no idea what caused the problem. We had the same versions of the .NET Framework and Visual Studio 2008 installed on all our machines. The code was exactly the same. Apart from the build machine being Windows Server 2003 and out development machines being Windows XP, I can’t think of any other differences. But somehow the code libraries weren’t getting copied in the same way.
Just another adventure on our way toward the Beta release…
I ran into a problem yesterday. I’d sent a HTTP POST request to a collection of resources on our RESTful web service. Our server responded with an HTTP 201: Created status code and the URI of the new resource in the Location header.
And then… nothing happened.
This was not what I was expecting. I expected my web browser to follow up with a GET request to the URI I’d provided. But Firefox 3 wasn’t biting. A problem with Firefox? I checked in IE8 and Google Chrome and got the same behavior.
Had I misread the HTTP spec? Did I misunderstand the REST pattern? I grabbed for my worn copy of RESTful Web Services. Nope. HTTP 201 seemed to be the right status for this situation.
Had I blundered into some common error? I checked Stefan Tilkov’s useful list of REST Antipatterns. But I couldn’t find anything that quite matched my situation.
I started Googling, but couldn’t find much apart from this question about HTTP Post on Stack Overflow. There were some cryptic responses (to which I’ve added my own answer now).
Eventually, I discovered what I needed to know from Ben Ramsey’s article on HTTP redirection. It’s part of his series discussing RFC 2616, which describes the HTTP/1.1 protocol.
The answer is that while web service clients will often “take the hint” provided by a HTTP 201: Created response, web browsers won’t. If you actually want a web browser to go somewhere else, you need to send a status code in the 3xx series. In this situation, the status code you want is HTTP 303: See Other.
Once I changed the status code returned by the server, all the web browsers followed up the response with a GET to the new URI.
If you’ve ever tried to write Add-ins for Microsoft Office, you know that it can be a pretty intimidating task. Sure the splash screens might look the same, but underneath, Office is a whole collection of different versions of different products, and this becomes really apparent when you look under the hood at the various API interfaces.
There have been several attempts by Microsoft to add consistency to the way that solutions are developed on the office platform (with Visual Studio Tools for Office being the latest, and probably best entry), but when it comes down to it, to deploy anything really useful, you have to resort to learning 4 different versions of 5 different object models.
Or do you? As you fumble your way through looking for sample code to make your life easier, there’s a high probability that you’ll end up on the Add-in Express site. When I first came across these guys, I checked out their claim that their product, Add-in Express, allows you to “Make office programming fast, comfortable and trouble-free”. I snorted.
“C’mon. Nothing can do that…” I then hit the back button and clicked some link to Experts-Exchange and auto-scrolled all the way to the bottom. You can’t believe everything you read on the Internet, right?
Much later, Dean found another positive review for the Add-In Express guys on StackOverflow, and as we were about to begin a new iteration of our Office add-ins, he suggested that we should give them a try. I spoke to Andrei about getting a demonstration license, and installed the toolkit to build the next version of our Outlook Add-in. Within 2 days, I was converted. Add-in Express is a remarkable piece of software.
Using Add-in Express is weird, but then, writing Office Add-ins is weird, so I guess that makes sense. Rather than have a traditional WYSIWYG designer, there is a canvas that allows you to add big icon-like controls, and then you set those controls’ properties through various properties dialogs. You handle events, write module level code, add references and any control you like.
When you’ve configured these things to your liking, you simply register the add-in from the build menu, and then start your target office application. Your add-in is configured for you. If you want to debug it, you just attach to the process, and step through your code. It has dramatically improved the reliability, speed and most importantly development time for our MS Office integration.
Add-in Express also adds a setup project to your solution, and builds you the MSI as you go. When you want to deploy your add-In, you simply run the MSI on the target machine.
Support from the Add-in Express guys via their forum was prompt and very helpful. It became patently clear to me that these guys have already fallen into, and successfully gotten out of, all of the traps, potholes and tricks that are awaiting you in the mysterious world of Office Development. If you are planning on doing some serious Office Integration, this kind of knowledge is invaluable. Highly recommended.
I spent Sunday afternoon battling an odd WCF error.
System.InvalidOperationException: Incoming message for operation [your operation here] contains an unrecognized http body format value ‘Xml’. The expected body format value is ‘Raw’. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.
Troubleshooting this issue sucked. Here’s the deal: WCF helpfully attempts to parse any incoming “text/xml” requests automatically. If you’ve defined the input parameter on a WebInvoke operation to be a Stream, WCF can’t bind to the method and returns an HTTP 400.
There’s two ways to solve this problem: Change the input parameter from Stream to XmlElement, or configure WCF to treat this request as Raw. I picked the former method. Carlos Figueira explains the latter method.
If folks are interested, I can post some more detail about the problem and the resolution. For now, I have to finish making things work.
Edit: So here’s the rest of the story, since Brad asked.
I wasn’t sure exactly what triggered the issue. I got this behavior with just one WebInvoke and one WebGet operation using the same URI template. What I’d done was to create a generic ObjectService that exposed the same RESTian operations for several different types of objects. The particular operation in question looked something like this:
Originally, PostListAsXml had accepted a Stream. That seemed to work in other places, but then I started noticing the InvalidOperationException messages.
I think the right way to solve this problem is to follow Carlos’ advice, and create a new WebContentTypeMapper-derived class. But I didn’t have time to figure out exactly where to plug it in, and I was afraid that I might introduce other problems. I just didn’t know enough about the inner workings of WCF to know whether that was a safe operation.
Since we hadn’t shipped the interface yet, I was free to change the return type from Stream to XmlElement for the one or two WebInvoke operations that were returning errors. Fewer lines of code needed to change, and I knew I wouldn’t break anything else.
Of course, I’m probably just setting myself up for more pain down the road, but sometimes you just need to get things done, y’know?
Anyway, since I’ll likely revisit this decision in a later release, I’d love to hear what other folks did in this situation.