如何使用WCF服务通过客户端将数据绑定到DropDownList

本文关键字:数据绑定 DropDownList 客户端 过客 何使用 WCF 服务 | 更新日期: 2023-09-27 18:13:43

我是WCF服务的新手。我想在ASP.NET中使用WCF服务,通过jQuery将数据绑定到DropDownList

如何使用WCF服务通过客户端将数据绑定到DropDownList

这是一个简单的$.ajax(..)调用http://api.jquery.com/jQuery.ajax/

在WCF中,您可以创建Rest Service(返回JSON(并在jQuery 中使用此JSON响应

http://msdn.microsoft.com/en-us/netframework/dd547388

互联网上有很多例子。

c#中的示例(Atom提要(:

   [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("someone@microsoft.com"));
           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);
          }
    }

在svc中,您只需要添加(Factory部分(:

<%@ ServiceHost Language="C#" Debug="true" Service="RssReader.Wcf.NewsFeed" CodeBehind="NewsFeed.svc.cs" Factory=System.ServiceModel.Activation.WebServiceHostFactory%>

编辑:

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

重要的部分是<serviceMetadata httpGetEnabled="true"/>,在这种情况下,您不需要定义任何端点