Hi all,
Today I spent some time wrinting a wrapper for an old REST service to make it read its data from a newer service. Unfortunately it seemed to be a little more complicated than I thought. As I just thought I’d have finished my work, I got the following error message:
(The remote server has responded with an unexpected answer: Method Not Allowed.)
Oops? A protocol error? What have I done? That nettled me that much that I decided to fix it instead of hurry myself and write a workaround for it. At first I thought it could be a configuration fault … but that it wasn’t … after I built a test-solution in VisualStudio for this structure, I could confirm my suspicion. The above named “method” in the error message has been the kind of transmission between the services. My REST-service expected a GET-request, but strangely my client sent a the request via POST:
Because of this I checked the definition of my contracts, if my fault could be there, but everything seemed to be right. Originally I used the WebGet attribute, but also the WebInvoke with “Method”=”GET” made no difference.
After I sat there for some time and couldn’t believe that it should be an error of WCF itself, I put a web-form for, testing reasons, in the same directory as my *.svc file and copied the service request in there … it worked:
So let’s note down – if I call a REST-service by another REST-service with a REST-client, I get as method alwas „POST“ … if I copy exactly the same code and configuration into a web-form and invoke it there, I get a „GET“-request (if I want to) … for the moment that seems to be a problem I can’t fix myself.
But even if you can’t get it to work THAT way, you could still use „POST“ instead of the „GET“ method. This will work in both places. The only negative thing is that you can’t call the service directly by opening the specific request in your browser. If you can’t use another method than “GET”, you could still use the HttpWebRequest directly for invoking the service.