2011-11-04 3 views

답변

2

그것은 당신이 인터넷에서 예를 들어 많은

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

jQuery를

이 JSON 응답을 나머지 서비스 (귀국일 JSON)을 생성하고 소비 할 수있는 WCF에서 간단한 $.ajax(..) 전화 http://api.jquery.com/jQuery.ajax/

입니다. C#에서

샘플 (아톰 피드) :

[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); 
      } 
    } 

및 SVC에 당신은 (공장 부분)를 추가해야합니다 편집

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

중요 부분은입니다. 그 시나리오에서은 어떤 종단점을 정의 할 필요가 없다.

+0

감사의 말을 전합니다. 웹 구성 파일에 필요한 구성이 있는지 알고 싶습니까? – YogeshWaran

+0

편집에 필요한 구성을했습니다. –

+0

답장을 보내 주셔서 감사합니다. WCF의 간단한 예가 있습니다. 나는 단지 학습자이다. 쉬운 예제를 원합니다 ... – YogeshWaran

관련 문제