tags:

views:

1778

answers:

6

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.

+3  A: 

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

AgileJon
That's what I did first - and then I went to my code and first added a using statement to System.ServiceModel and that was recognized but System.ServiceModel.Web is not recognized. Odd right?!
Start with a fresh project, add a reference to that dll and make sure your using statement works. If not, you're having other problems.
Terry Donaghe
Try cleaning your project and then building. Also try restarting Visual Studio
AgileJon
OK - I feel I'm getting somewhere... When go to add a reference to the project and the 'Add Reference' window comes up, under the .NET tab, I CANNOT find the System.ServiceModel.* dlls. It does look like I have them in my GAC (GAC_MSIL), but I guess they're not 'registered' properly or something. How can I make sure they come up properly in VS?
+1 it helped me.
Wodzu
A: 

What version of Visual Studio are you using?

Also, what is the target framework set to for your project?

John Saunders
I added some more UPDATES to my initial problem scope that might assist you. VS 2008 SP1, and 3.5
A: 

using System.ServiceModel.Web;

A: 

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 Refenences 5: Build

..and VS found it??

Lee Smith
+1  A: 

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

Hossam
A: 

In "project properties" make sure your "target framework" is set to : .NET Framework 4

and not: .NET Framework 4 Client Profile, or any lower .NET version.

Also, if possible use VS 2010.

--DBJ

DBJDBJ