WCF REST Webinvoke not found
Asked Answered
H

1

17

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 ??

Honor answered 25/4, 2011 at 12:37 Comment(0)
F
38

WebInvokeAttribute is in separate assembly System.ServiceModel.Web.dll. Did you reference that assembly? Also you must add 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.

Favrot answered 25/4, 2011 at 12:39 Comment(10)
What version of .NET/WCF are you using?Favrot
I am using .NET 4.0 (not 4.0 Client Profile)Honor
I have never heard about WebContentType attribute and as I know it is not part of WCF.Favrot
What type of project are you using?Favrot
@Ladislav : I'm facing the same issue. Also, I don't see reference to System.ServiceModel.Web in add reference dialog. I'm using Visual Studio 2010 (.net 4.0). Can you help me if i'm missing something ??Showy
Hmmm...dont mind but what specific client profile are you asking? I'm new to web and working on creating a simple page in html5 and need to call a webservice.Showy
list of namespace added: using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text;Showy
I am also facing same problem. i am using Visual Studio 2010Cormorant
somehow ReSharper isn't able to add the reference automaticallyAntonetta
@Showy what was the solution?Contempt

© 2022 - 2024 — McMap. All rights reserved.