Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Service Returning "Method Not Allowed"

In the process of developing my first WCF service and when I try to use it I get "Method not Allowed" with no other explanation.

I've got my interface set up with the ServiceContract and OperationContract:

    [OperationContract]
    void FileUpload(UploadedFile file);

Along with the actual method:

    public void FileUpload(UploadedFile file) {};

To access the Service I enter http://localhost/project/myService.svc/FileUpload but I get the "Method not Allowed" error

Am I missing something?

like image 849
jdiaz Avatar asked Sep 03 '08 04:09

jdiaz


2 Answers

If you are using the [WebInvoke(Method="GET")] attribute on the service method, make sure that you spell the method name as "GET" and not "Get" or "get" since it is case sensitive! I had the same error and it took me an hour to figure that one out.

like image 71
darthjit Avatar answered Oct 28 '22 07:10

darthjit


Your browser is sending an HTTP GET request: Make sure you have the WebGet attribute on the operation in the contract:

[ServiceContract]
public interface IUploadService
{
    [WebGet()]
    [OperationContract]
    string TestGetMethod(); // This method takes no arguments, returns a string. Perfect for testing quickly with a browser.

    [OperationContract]
    void UploadFile(UploadedFile file); // This probably involves an HTTP POST request. Not so easy for a quick browser test.
 }
like image 66
Ries Avatar answered Oct 28 '22 07:10

Ries