Pushing default RSS or ATOM path from WCF, clients only

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

Contract

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

      

Using

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

      

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

Update Adding [WebGet (UriTemplate = ")] only allows me part of this path. 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 channels like http://weblogs.asp.net/scottgu/atom.aspx which changes to http://weblogs.asp.net/scottgu/atom.aspx/

0


source to share


2 answers


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



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

0


source


I think there is a way to do this using OperationContext / WebOperationContext. I am forgetting the exact details, but see for example this example that creates an OperationContextScope on a channel

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



at this point you can access eg. OperationContext.Current.OutgoingMessageProperties (maybe set .Via for your desired Uri) or WebOperationContext.Current.OutgoingWebRequest if you want to set, for example, HTTP headers or "method" (http verb). I think maybe gouging OperationContext.Current.OutgoingMessageProperties.Via does what you need.

0


source







All Articles