代码之家  ›  专栏  ›  技术社区  ›  bendewey

从wcf命中默认rss或atom路径,仅限客户端

  •  0
  • bendewey  · 技术社区  · 16 年前

    我正在尝试编写一个简单的wcf包装器,以将一个syndicationfeed作为客户端加载。

    合同

    [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 )并且由于我希望这个扩展到任何提要,所以我并不总是知道提要的名称。是否可以指定一个属性或属性来使用默认端点地址而不是追加方法名?

    更新 添加[webget(uritemplate=)]只会让我在这方面有一部分收获。它适用于 http://channel9.msdn.com/Feeds/RSS ,将其更改为 http://channel9.msdn.com/Feeds/RSS/ ,但它不适用于其他订阅源,如 http://weblogs.asp.net/scottgu/atom.aspx 改成 http://weblogs.asp.net/scottgu/atom.aspx/

    2 回复  |  直到 14 年前
        1
  •  0
  •   Brian    16 年前

    我认为将webgetattribute上的uritemplate更改为空字符串就可以了。

    http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.uritemplate.aspx

        2
  •  0
  •   Brian    16 年前

    我认为有一种方法可以使用operationcontext/weboperationcontext来实现。我忘记了确切的细节,但是请看这个例子,它在通道上创建了一个operationcontextscope

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

    在这一点上,您可以访问例如操作上下文、Currut.OutGooMeMeaGeice属性(可能设置.VIs到所需URI),或者WebOperationContext.Current.OutgoingWebRequest,如果您想设置HTTP头或“方法”(HTTP谓词)。我认为poking operationcontext.current.outgoingMessageProperties.via可以满足您的需要。

    推荐文章