Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF - Cannot resolve [WebGet] symbol - what am I doing wrong?

Tags:

c#

wcf

I am working on a REST WCF project and when I implement the following code, it complains that it can't resolve the WebGet class? What am I missing?

I tried importing the System.ServiceModel.Web namespace but it can't find it even though I referenced it. The "Web" in System.ServiceModel.Web does not register when I register it in a using statement on top of my code.

Basically, what do I need to implement such WCF REST concepts like WebGet, WebInvoke, UriTemplate, etc?

UPDATE: After some feedback and thinking about this a little bit more what I've done, it seems that the DLLs (System.ServiceModel & System.ServiceModel.Web) do not come up via the 'Add Reference' window when I go to add a project reference. When I first started the project, FYI, since these assemblies did not come up at first, I went 'searching' for them, and copied them to a temp folder so I can reference them and thus, I guess I am having the resolve issues. So, now that I am at this point, how can I get my VS to recognize/register these WCF REST DLLs? Thanks!

UPDATE: I believe I am update-to-date on everything: developing on VS 2008 SP1 - I try to download the latest SPs, downloaded the REST Preview 2 Starter Kit, developing against 3.5 Framework, trying to create a WCF REST layer to ultimately be consumed by Silverlight 2 client.

This is what I have:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using UtilityClasses;
using Microsoft.ServiceModel.Web;
using Microsoft.Http;

namespace WcfRestService
{
    [ServiceContract]
    public interface IRestService
    {
        [OperationContract(Name = "Add")]
        [WebGet(UriTemplate = "/")]   // ** can't compile here **
        int Add();
    }

}

Any advice will be greatly appreciated it.

like image 366
user118190 Avatar asked Jun 24 '09 17:06

user118190


3 Answers

You need to reference the System.ServiceModel.Web DLL.

Right-click the 'References' folder in your project and choose 'Add Reference...'. Scroll down to System.ServiceModel.Web and click 'OK'.

like image 122
AgileJon Avatar answered Oct 15 '22 00:10

AgileJon


Just a one thought, you might be targeting your project to .Net Client Profile which exposes limited namespaces. you may need to check the target framework setting at your project properties.

I have faced that with a WCF project not finding System.ServiceModel.Web untill I changed the default framework settings.

HTH

like image 25
Hossam Avatar answered Oct 15 '22 02:10

Hossam


This happened to me too.

I did this:

  1. Delete System.Service.Web from References
  2. Build
  3. Clean Project
  4. Add System.Service.Web to References
  5. Build

..and VS found it??

like image 9
Lee Smith Avatar answered Oct 15 '22 00:10

Lee Smith