tags:

views:

66

answers:

2

Hello

I try to add an OperationContract in WCF syndicationlibrary template but the URI template seems not to be matched (or maybe I'm missing something else).

When I try accessing to http://myserver:8738/Design_Time_Addresses/SyndicationServiceLibrary2/ShowDocument?url=http://www.test.com

function ShowDocument does not fire and I get a 404 error.

Any help would be appreciated.

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;  
        }  
    }
}
A: 

Can't try it myself right now - just a few idea off the top of my head:

Have you tried using Url encoding for your parameter??

http://......./ShowDocument?url=http%3a%2f%2fwww.test.com

This might help - use the HttpUtility.UrlEncode method from the System.Web namespace to url encode (and decode) parameters that need to go into the URL itself.

Another idea: how about creating a URL template and passing the URL into the ShowDocument method as a string??

[OperationContract]
[WebInvoke(UriTemplate = "/ShowDocument?url={target}", BodyStyle = WebMessageBodyStyle.Bare)]
int ShowDocument(string target);

and see if it works then?

marc_s
A: 

Thanks for your answer marc_s.
I'm ashamed to tell you my problem was :

new Uri("http://myserver:8738/Design_Time_Addresses/SyndicationServiceLibrary2...

where "myserver" was NOT the good one.
I finally managed to do the whole thing using url template with parameter.

Bruno