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?
-
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.Tim– Tim2011-09-07 05:40:22 +00:00Commented 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 onceVictor– Victor2011-09-07 05:52:41 +00:00Commented 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?Tim– Tim2011-09-07 06:01:23 +00:00Commented Sep 7, 2011 at 6:01
-
yes Tim please give any link if you know ...Victor– Victor2011-09-07 06:03:59 +00:00Commented 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.Tim– Tim2011-09-07 06:08:19 +00:00Commented Sep 7, 2011 at 6:08
|
Show 1 more comment
1 Answer
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>