views:

187

answers:

2

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/

A: 

I think changing the UriTemplate on WebGetAttribute to the empty string will do it.

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

Brian
see updated question with more problems
bendewey
Lame, but I think you maybe can trim off the last part of the Uri and put it in the UriTemplate, e.g. Uri("http...scottgu"), WebGet(UriTemplate="atom.aspx")
Brian
The url is a user input
bendewey
A: 

I think there's a way to do it using the OperationContext/WebOperationContext. I forget the exact details, but see e.g. this example which creates an OperationContextScope on the channel

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

at which point you can access e.g. OperationContext.Current.OutgoingMessageProperties (maybe set the .Via to the desired Uri), or WebOperationContext.Current.OutgoingWebRequest if you want to set, say, the HTTP headers or the 'method' (http verb). I think maybe poking OperationContext.Current.OutgoingMessageProperties.Via does what you need.

Brian