Я пытаюсь добавить шаблон OperationContract в шаблон для синдикации библиотеки WCF, но шаблон URI, похоже, не соответствует (или, может быть, я что-то упускаю).
Когда я пытаюсь получить доступ к http://myserver:8738/Design_Time_Addresses/SyndicationServiceLibrary2/ShowDocument?url=http://www.test.com
функция ShowDocument не запускается, и я получаю ошибку 404.
Любая помощь будет оценена.
IFeed1.cs:
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 SyndicationServiceLibrary2
{
// NOTE: If you change the interface name "IFeed1" here, you must also update the reference to "IFeed1" in App.config.
[ServiceContract]
[ServiceKnownType(typeof(Atom10FeedFormatter))]
[ServiceKnownType(typeof(Rss20FeedFormatter))]
public interface IFeed1
{
[OperationContract]
[WebGet(UriTemplate = "*", BodyStyle = WebMessageBodyStyle.Bare)]
SyndicationFeedFormatter CreateFeed();
[OperationContract]
[WebInvoke(UriTemplate = "/ShowDocument?*", BodyStyle = WebMessageBodyStyle.Bare)]
int ShowDocument();
// TODO: Add your service operations here
}
}
Feed1.cs:
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 SyndicationServiceLibrary2
{
// NOTE: If you change the class name "Feed1" here, you must also update the reference to "Feed1" in App.config.
public class Feed1 : IFeed1
{
public int ShowDocument()
{
int test = 0;
return test;
}
public SyndicationFeedFormatter CreateFeed()
{
// Create a new Syndication Feed.
SyndicationFeed feed = new SyndicationFeed("Feed Title", "A WCF Syndication Feed", null );
List<SyndicationItem> items = new List<SyndicationItem>();
// Create a new Syndication Item.
SyndicationItem item = new SyndicationItem("An item", "Item content", new Uri("http://myserver:8738/Design_Time_Addresses/SyndicationServiceLibrary2/ShowDocument?url=http://www.test.com"));
items.Add(item);
feed.Items = items;
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;
}
}
}