0

I'm trying to write a simple WCF Wrapper to load a SyndicationFeed as a client.

Contract

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

Usage

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

Question The problem is that the service is appending the method name to the url (ie. the above url would call http://channel9.msdn.com/Feeds/RSS/GetFeed), and since I want this to be extended to any feed I don't always know the name of the feed. Is there an attribute or property that I can specify that will use the default endpoint address instead of appending a method name?

Update Adding the [WebGet(UriTemplate="")] only gets me part of the way there. It works for http://channel9.msdn.com/Feeds/RSS, changes it to http://channel9.msdn.com/Feeds/RSS/, but it doesn't work for other feeds like http://weblogs.asp.net/scottgu/atom.aspx which gets changed to http://weblogs.asp.net/scottgu/atom.aspx/

4

2 回答 2

0

我认为将 WebGetAttribute 上的 UriTemplate 更改为空字符串即可。

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

于 2008-12-16T20:00:29.157 回答
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 可以满足您的需要。

于 2008-12-17T15:14:08.017 回答