When I was developing my demos for PDC10 I ran into a problem. I was using some new HTTP activities for the next release of WF and invoking a simple console application with an HTTP POST. For some strange reason I ran into the following error
POST http://127.0.0.1:8080/Marketing HTTP/1.1
HTTP/1.1 415 Cannot process the message because the content type
'application/xml' was not the expected type 'text/xml; charset=utf-8'.
Date: Wed, 27 Oct 2010 20:00:06 GMT
I have done a fair bit of development with WCF but I had never seen this error message before. I was so sure that my code was correct I immediately assumed it must be a problem with our new HttpPost activity so first I decided to check with our test team to see if they had a working test. When I found out they did we began looking more closely and I found… a copy paste bug.
That’s right, in my hosting code it turned out that I was using ServiceHost instead of WebServiceHost to host my WCF WebHttp service. In most cases when service host detects that your service (or it’s configuration) is somehow invalid it throws an exception when you try to open the host. For some strange reason (bug?) in this case it does not throw an exception but happily starts accepting requests and throwing 415 when you invoke it.
The solution of course is to use WebServiceHost instead of ServiceHost. Hopefully this will save somebody out there some time.