1

I want use WCF WebApi in a regular ASP.NET C# project. Already I have created WCF WebApi in MVC application but I want to create in normal ASP.NET. Are there any sample links to show this?

6
  • There are several flavors of WCF - which one are you talking about? Are you looking for one that uses SOAP, or REST? Please clarify your question as to what you're looking for. Commented Sep 7, 2011 at 5:40
  • Hi thank you for giving response.wcf.codeplex.com/wikipage?title=WCF%20HTTP i have fallow above link for webapi please check it once Commented Sep 7, 2011 at 5:52
  • So you want to do essentially the same thing in the tutorial, only using Web Forms instead of MVC? Commented Sep 7, 2011 at 6:01
  • yes Tim please give any link if you know ... Commented Sep 7, 2011 at 6:03
  • I couldn't find any with a quick Google search. You could try it yourself (consider it a learning opportunity) :). You also might want to take a look at Introducing WCF WebHttp Services in .NET 4 - it might be of value, though it's not the Web API. Commented Sep 7, 2011 at 6:08

1 Answer 1

5

File / New Project / ASP.NET Application

NuGet: Install-Package WebApi.All

Add a new ContactsResource

[ServiceContract]
public class ContactsResource {
    [WebGet(UriTemplate = "")] 
    public List<Contact> Get() {
        return new List<Contact>()
                {
                    new Contact()
                        {
                            Name = "Alex"
                        }
                };
     }
}

Add a Contact class

public class Contact {
    public string Name { get; set; }
}

Edit the Global.asax.cs

Modify Application_Start:

void Application_Start(object sender, EventArgs e) {
    // Code that runs on application startup
    RouteTable.Routes.MapServiceRoute<ContactsResource>("contacts");
}

Hit F5 and navigate to http://mywebsite/contacts

Done.

<ArrayOfContact>
    <Contact>
        <Name>Alex</Name>
    </Contact>
 </ArrayOfContact>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.