|
using System;
using System.Collections.Generic;
using System.IO;
using System.ServiceModel.Syndication;
namespace WCFRest
{
/// <summary>
/// Implements the interface
/// </summary>
public class MathService : IMath
{
/// <summary>
/// Adds two numbers
/// </summary>
/// <param name="x">the first number</param>
/// <param name="y">the second number</param>
/// <returns></returns>
public int Add(int x, int y)
{
return x + y;
}
/// <summary>
/// Returns a sample stream
/// </summary>
/// <returns></returns>
public Stream GetStream()
{
return File.OpenRead(@"c:\windows\notepad.exe");
}
public SyndicationFeedFormatter GetFeed(bool rss)
{
List<SyndicationItem> items = new List<SyndicationItem>();
// make link to notepad
SyndicationItem item = new SyndicationItem();
item.Title = new TextSyndicationContent("Notepad on server.");
item.Links.Add(new SyndicationLink(new Uri("http://localhost:41000/MathService/web/notepad")));
item.PublishDate = DateTime.Now;
items.Add(item);
SyndicationFeed feed =
new SyndicationFeed
("Notepad Feed",
"Feed with links to notepad.exe",
new Uri("http://www.google.be"), // alternate link is google
items);
feed.LastUpdatedTime = DateTime.Now;
if (rss)
{
return new Rss20FeedFormatter(feed);
}
return new Atom10FeedFormatter(feed);
}
/// <summary>
/// Posts sample data
/// </summary>
public void PostData(PostedData data)
{
if (data == null)
{
Console.WriteLine("null");
return;
}
Console.WriteLine("Received: " + data.FirstName + " " + data.LastName);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
C# developer for a few years and specialized in an age past in C and Visual Basic 6. Having had the opportunity to work with .NET 3.5 since it was released, I've been using it with great success (big thanks to you LINQ team) to create functionality faster and better than was possible in 2.0, and am now looking into .NET 4.0. Currently I work at Kluwer Technology Services where I'm a technical lead, helping my fellows, architecting solutions and spreading the knowledge. I’m also an MCPD for .NET 2.0 and 3.5.