.net 找不到 WCF REST Webinvoke

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5778388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:30:26  来源:igfitidea点击:

WCF REST Webinvoke not found

.netwcfrest.net-4.0webinvoke

提问by Ankit

Following is the code i am using in my test app:

以下是我在测试应用程序中使用的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.IO;

namespace MyWCFServices
{
    [ServiceContract]
    interface IHelloWorldService
    {
        [OperationContract]
        String GetMessage(String name);

        //[OperationContract]
        //[WebInvoke(Method = "PUT",UriTemplate = "File/{fileName}")]
        //[WebContentType("application/octet-stream")]
        // bool UploadFile(string fileName, Stream fileContents); 
        [OperationContract]
        [WebInvoke(UriTemplate = "UploadFile/{fileName}")]
        void UploadFile(string fileName, Stream fileContent); 
    }
}

It gives and error on compilation for webinvoke. Any idea about the same ??

它在为 webinvoke 编译时给出错误。关于相同的任何想法?

回答by Ladislav Mrnka

WebInvokeAttributeis in separate assembly System.ServiceModel.Web.dll. Did you reference that assembly? Also you must add using System.ServiceModel.Web;

WebInvokeAttribute位于单独的程序集 System.ServiceModel.Web.dll 中。你参考那个程序集了吗?你也必须添加using System.ServiceModel.Web;

Edit:

编辑:

To use System.ServiceModel.Web.dll assembly you must use at least .NET 3.5 and you can't use .NET 4.0 Client Profile.

要使用 System.ServiceModel.Web.dll 程序集,您必须至少使用 .NET 3.5,并且不能使用 .NET 4.0 Client Profile。