WCF服务返回"不允许的方法" [英] WCF Service Returning "Method Not Allowed"

查看:933
本文介绍了WCF服务返回"不允许的方法"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发我的第一个WCF服务的过程中,当我尝试使用它,我得到不允许的方法,没有别的解释。

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.

我有我的界面设置与的ServiceContract和OperationContract的:

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) {};

要进入服务我输入<一个href="http://localhost/project/myService.svc/FileUpload">http://localhost/project/myService.svc/FileUpload 但我得到了不允许的方法错误

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

我缺少的东西?

推荐答案

您的浏览器发送一个HTTP GET请求:请确保您有关于合同的操作WebGet属性:

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.
 }

这篇关于WCF服务返回&QUOT;不允许的方法&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆