none
How to deploy and call WCF SyndicationFeed? RRS feed

  • Question

  • Hello,

    I created WCF Syndication-Sevice Library in VS 2019 and named it "news". (i created it from standard VS Template, without any customising). 

    If I start this Project in VS, and it works good under: http://localhost:8733/Design_Time_Addresses/news/Feed1/

    (I see an RSS feed)

    Than, I deploy it with the right mouse to output folder and became there news.Feed1.svc, web.config and bin-Folder.

    Than I copy it to the Folder on IIS : C:\inetpub\wwwroot\test  . Thist is a web-application-folder with the Pool .NET 4.5.

    If I call on IIS Server the URL http://localhost/test/news.Feed1.svc - they tell me that I made a service and it ok, and i can test it with http://localhost/test/news.Feed1.svc?wsdl etc. So I think it works.

    BUT:

    I can't call it on IIS-Server to became it as RSS-Feed.

    if I call  http://localhost:8733/Design_Time_Addresses/news/Feed1/ on the IIS server, they tell me "site cannt not shown"

    if I call   http://localhost/Design_Time_Addresses/news/Feed1/, they give me back 404.0

    also http://localhost/test/news/Feed1 give me back 404 and http://localhost/test/news.Feed1 give me back 404.

    How can I achive this goal?

    Many Thanks

    P.S.

    I think, I should to Host this Syndication Service either such console app or IIS, right?

    Web.config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <system.serviceModel>
        <services>
          <service behaviorConfiguration="MyServiceTypeBehaviors" name="news.Feed1">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8733/Design_Time_Addresses/news/" />
              </baseAddresses>
            </host>
            <endpoint contract="news.IFeed1" address="Feed1" binding="webHttpBinding" behaviorConfiguration="news.Feed1Behavior"/>
          </service>
        </services>
        <behaviors>
          
          <serviceBehaviors>
            <behavior name="MyServiceTypeBehaviors" >
              <serviceMetadata httpGetEnabled="true" />
            </behavior>
          </serviceBehaviors>      
          
          <endpointBehaviors>
            <behavior name="news.Feed1Behavior">
              
              <webHttp/>
              
            </behavior>
          </endpointBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Syndication;
    using System.ServiceModel.Web;
    using System.Text;
    
    namespace news
    {
        // HINWEIS: Mit dem Befehl "Umbenennen" im Menü "Umgestalten" können Sie den Schnittstellennamen "IFeed1" sowohl im Code als auch in der Konfigurationsdatei ändern.
        [ServiceContract]
        [ServiceKnownType(typeof(Atom10FeedFormatter))]
        [ServiceKnownType(typeof(Rss20FeedFormatter))]
        public interface IFeed1
        {
    
            [OperationContract]
            [WebGet(UriTemplate = "*", BodyStyle = WebMessageBodyStyle.Bare)]
            SyndicationFeedFormatter CreateFeed();
    
            // TODO: Hier Dienstvorgänge hinzufügen
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Syndication;
    using System.ServiceModel.Web;
    using System.Text;
    
    namespace news
    {
        // HINWEIS: Mit dem Befehl "Umbenennen" im Menü "Umgestalten" können Sie den Klassennamen "Feed1" sowohl im Code als auch in der Konfigurationsdatei ändern.
        public class Feed1 : IFeed1
        {
            public SyndicationFeedFormatter CreateFeed()
            {
                // Einen neuen Syndication-Feed erstellen.
                SyndicationFeed feed = new SyndicationFeed("Feed Title", "A WCF Syndication Feed", null);
                List<SyndicationItem> items = new List<SyndicationItem>();
    
                // Ein neues Syndication-Element erstellen.
                SyndicationItem item = new SyndicationItem("An item", "Item content", null);
    
                SyndicationItem item1 = new SyndicationItem(
                            "Item One",
                            "This is the content for item one",
                            new Uri("http://localhost/Content/One"),
                            "ItemOneID",
                            DateTime.Now);
    
                SyndicationItem item2 = new SyndicationItem(
                    "Item Two",
                    "This is the content for item two",
                    new Uri("http://localhost/Content/Two"),
                    "ItemTwoID",
                    DateTime.Now);
    
                SyndicationItem item3 = new SyndicationItem(
                    "Item Three",
                    "This is the content for item three",
                    new Uri("http://localhost/Content/three"),
                    "ItemThreeID",
                    DateTime.Now);
    
    
    
                items.Add(item);
                items.Add(item1);
                items.Add(item2);
                items.Add(item3);
    
                feed.Items = items;
    
                // Auf Grundlage der Abfragezeichenfolge ATOM oder RSS zurückgeben.
                // rss -> http://localhost:8733/Design_Time_Addresses/news/Feed1/
                // atom -> http://localhost:8733/Design_Time_Addresses/news/Feed1/?format=atom
                string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
                SyndicationFeedFormatter formatter = null;
                if (query == "atom")
                {
                    formatter = new Atom10FeedFormatter(feed);
                }
                else
                {
                    formatter = new Rss20FeedFormatter(feed);
                }
    
                return formatter;
            }
        }
    }



    • Edited by Interraptor Wednesday, November 13, 2019 1:17 PM
    Wednesday, November 13, 2019 1:10 PM

All replies

  • I have solved a Problem as follow:

    I created a new WebApplication ASP.NET empty.

    I added the Classes IFEED ans Feed

    than I instantinate this klasses  in code behind 

                Feed1 feed = new Feed1();
                SyndicationFeedFormatter ssf =  feed.CreateFeed();
                string sGuid = Guid.NewGuid().ToString();
                string path = Path.Combine(HttpContext.Current.Server.MapPath("/AppData") , "rss_"+ sGuid + ".xml");
                XmlWriter xw = XmlWriter.Create(path);
                
                //Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(ssf.Feed);
                //atomFormatter.WriteTo(xw);
    
                ssf.Feed.SaveAsRss20(xw);
                xw.Close();
                
                string xmlString = System.IO.File.ReadAllText(path);
                File.Delete(path);
    
                Response.Clear();
                Response.ContentType = "text/xml";
                Response.Write(xmlString);

    the ASPX backend as follow:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplicationNews.Default" %>
    Thats all.

    Wednesday, November 13, 2019 2:32 PM