Reputation: 2281
I am new to WCF services. I want to use WCF service in ASP.NET to bind data to a DropDownList
through jQuery.
Upvotes: 1
Views: 2005
Reputation: 4629
It's a simple $.ajax(..)
call
http://api.jquery.com/jQuery.ajax/
In WCF you can create Rest Service (return JSON) and consume this JSON response in jQuery
http://msdn.microsoft.com/en-us/netframework/dd547388
Lots of example in internet.
Sample in c# (Atom feeds):
[ServiceContract]
public interface INewsFeed
{
[OperationContract]
[WebGet]
Atom10FeedFormatter GetFeeds();
}
public class NewsFeed : INewsFeed
{
public Atom10FeedFormatter GetFeeds()
{
SyndicationFeed feed = new SyndicationFeed("My Blog Feed", "This is a test feed", new Uri("http://SomeURI"));
feed.Authors.Add(new SyndicationPerson("[email protected]"));
feed.Categories.Add(new SyndicationCategory("How To Sample Code"));
feed.Description = new TextSyndicationContent("This is a how to sample that demonstrates how to expose a feed using RSS with WCF");
SyndicationItem item1 = new SyndicationItem(
"Lorem ipsum",
"Lorem ipsum",
new Uri("http://localhost/Content/One"),
"ItemOneID",
DateTime.Now);
List<SyndicationItem> items = new List<SyndicationItem>();
items.Add(item1);
feed.Items = items;
return new Atom10FeedFormatter(feed);
}
}
and in svc you just need to add (Factory part):
<%@ ServiceHost Language="C#" Debug="true" Service="RssReader.Wcf.NewsFeed" CodeBehind="NewsFeed.svc.cs" Factory=System.ServiceModel.Activation.WebServiceHostFactory%>
Edited:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Important part is <serviceMetadata httpGetEnabled="true"/>
in that scenario you don't need to define any endpoints
Upvotes: 2