2008-12-16 77 views
0

我正在嘗試編寫一個簡單的WCF包裝器來將SyndicationFeed作爲客戶端加載。從WCF打印默認的RSS或ATOM路徑,僅客戶端

合同

[ServiceContract] 
public interface IFeedService 
{ 
    [OperationContract] 
    [WebGet(UriTemplate="")] 
    SyndicationFeed GetFeed(); 
} 

使用

using (var cf = new WebChannelFactory<IFeedService>(new Uri("http://channel9.msdn.com/Feeds/RSS"))) 
{ 
    IFeedService s = cf.CreateChannel(); 
    this.FeedItemsList.DataSource = s.GetFeed().Items; 
} 

問題的問題是,該服務是附加的方法名到URL(即上面的URL會叫http://channel9.msdn.com/Feeds/RSS/GetFeed),由於我希望將其擴展到任何Feed,但我並不總是知道Feed的名稱。是否有一個屬性或屬性可以指定使用默認端點地址而不是附加方法名稱?

更新添加[WebGet(UriTemplate =「」)]只讓我成爲那裏的一部分。它適用於http://channel9.msdn.com/Feeds/RSS,它改變http://channel9.msdn.com/Feeds/RSS/,但它並不適用於它被改爲http://weblogs.asp.net/scottgu/atom.aspx/

回答

0

我認爲有辦法做到這一點使用的OperationContext/WebOperationContext。我忘記了確切的細節,但請參閱本實施例中它創建信道上的OperationContextScope

http://social.msdn.microsoft.com/forums/en-US/wcf/thread/8f9f276a-e13f-4d06-8c1e-0bb6abd8f5fe

在哪些點可以訪問例如OperationContext.Current.OutgoingMessageProperties(可能會將.Via設置爲所需的Uri)或WebOperationContext.Current.OutgoingWebRequest(如果要設置HTTP標頭或「方法」(http動詞))。我認爲也許戳OperationContext.Current.OutgoingMessageProperties.Via做你需要的。