【问题标题】:how to bind data to DropDownList through client side using WCF service如何使用 WCF 服务通过客户端将数据绑定到 DropDownList
【发布时间】:2011-11-04 18:13:54
【问题描述】:

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

【问题讨论】:

    标签: c# jquery asp.net wcf


    【解决方案1】:

    这是一个简单的$.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>
    

    重要的部分是 &lt;serviceMetadata httpGetEnabled="true"/&gt; 在这种情况下您不需要定义任何端点

    【讨论】:

    • 谢谢哥们 我也想知道 webconfig 文件中是否需要任何配置?
    • 感谢您的回复,是否有 WCF 的简单示例。我只是学习者。我想要一些简单的例子...
    • 观看 Channel9 的网络广播
    猜你喜欢
    • 2012-02-11
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多