Using wcf to display SyndicationFeedFormatter OR IList <SyndicationItem>
I would like to expose SyndicationFeedFormatter with wcf and basicHttpBinding. I keep getting errors like below. I have included frontend / class and wcf web.config configuration.
I tried to expose the SyndicationFeedFormatter as well as the IList, but could not skip the next error. Could anyone have done this or has anyone confirmed what the problem is?
thanks - dave
Error message
System.ServiceModel.Dispatcher.NetDispatcherFaultException: Formatting threw an exception when trying to deserialize a message: When trying to deserialize the parameter http://tempuri.org/:GetFeaturesResult . The InnerException message was' Error at line 1 position 123. Element http://tempuri.org/:GetFeaturesResult 'contains data' http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication:Rss20FeedFormatter
My interface / contract looks like
[ServiceContract]
[ServiceKnownType(typeof(Atom10FeedFormatter))]
[ServiceKnownType(typeof(Rss20FeedFormatter))]
public interface IGetData {
[OperationContract]
SyndicationFeedFormatter GetFeatures();
[OperationContract]
IList<SyndicationItem> GetFeatures2();
}
My method looks like ...
public SyndicationFeedFormatter GetFeatures()() {
// Generate some items...
SyndicationFeed feed = new SyndicationFeed() {
Title = new TextSyndicationContent("Mike Feed"),
Description = new TextSyndicationContent("Mike Feed Description")
};
feed.Items = from i in new int[] { 1, 2, 3, 4, 5 }
select new SyndicationItem() {
Title = new TextSyndicationContent(string.Format("Feed item {0}", i)),
Summary = new TextSyndicationContent("Not much to see here"),
PublishDate = DateTime.Now,
LastUpdatedTime = DateTime.Now,
Copyright = new TextSyndicationContent("MikeT!"),
};
return (new Rss20FeedFormatter(feed));
}
public IList<SyndicationItem> GetFeatures2() {
List<string> includeList = new List<string>();
includeList.Add("Feature");
IList<SyndicationItem> mylist = ReaderManager.GetFeedByCategory2(includeList, null, null);
return mylist;
}
My web.config looks like this
binding = "webHttpBinding" contract = "SLNavigationApp.Web.IGetData"> ->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="SLNavigationApp.Web.GetDataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
a source to share
I'm confused: are you using WebHttpBinding or BasicHttpBinding? You should definitely use the former and it should just work.
If you're trying to use BasicHttpBinding, don't you share why? The SyndicationFeedFormatter classes are not DataContracts or XmlSerializable (which is what BasicHttpBinding needs to support), so it probably won't work in this case if you haven't done a little extra work. What I will probably try to work around this would be to simply change my ServiceContract to return Message objects, namely:
[ServiceContract]
[ServiceKnownType(typeof(Atom10FeedFormatter))]
[ServiceKnownType(typeof(Rss20FeedFormatter))]
public interface IGetData {
[OperationContract]
Message GetFeatures();
}
...
SyndicationFeedFormatter frm = new Rss20FeedFormatter(feed);
return Message.CreateMessage(
MessageVersion.None, "GetFeatures",
new FeedBodyWriter(frm)
);
...
class FeedBodyWriter : BodyWriter {
SyndicationFeedFormatter formatter;
public FeedBodyWriter(SyndicationFeedFormatter formatter) : base(false) {
this.formatter = formatter;
}
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) {
formatter.WriteTo(writer);
}
}
a source to share
Cool, I was wondering why my service is not generating browser content. I also used basicHttpBinding (because all other calls are from Silverlight).
As an unrelated alert:
You can change: from i to new int [] {1, 2, 3, 4, 5}
To: from i to Enumerable.Range (1, 5)
This can be very handy! I usually use it as "Enumerable.Range (1, pagecount)" in an XLINQ query when I pull the paged XML data from the server.
a source to share