Hi everyone, I have a requirement to consume a RESTful service in a .NET 4.0 app. I have some sample code provided by the client that uses WebRequests to talk to the service but I thought WCF would be a better fit since I'm using .NET 4.0.
I saw the WCF Web API <http://wcf.codeplex.com/wikipage?title=WCF%20HTTP>on CodePlex, but the FAQ <http://wcf.codeplex.com/wikipage?title=WCF%20Web%20API%20FAQ> says it can't be used in production. Then there's it's predecessor, the REST Starter Kit Preview 2 <http://aspnet.codeplex.com/releases/view/24644>. The "Preview 2" bit doesn't fill me with confidence and I can't find anything that clearly indicates whether it can be deployed to end users in a desktop app. Maybe I need to look harder. I threw together a quick sample app making use of the WebGet attribute in System.ServiceModel.Web... [ServiceContract] public interface IService { [WebGet(UriTemplate = "api/projects")] void GetProjects(); } class Program { static void Main(string[] args) { using (var channelFactory = new ChannelFactory<IService>(new WebHttpBinding(WebHttpSecurityMode.Transport), "https://test.example.com")) { channelFactory.Endpoint.Behaviors.Add(new WebHttpBehavior()); var channel = channelFactory.CreateChannel(); channel.GetProjects(); } } } This appears to be making the proper call to the service but it requires basic HTTP authentication so it fails. I have the username and password but how do I set it? The other issue I have is how to process the data returned by this call (just using void above while I get it talking). I have documentation about the structure of the XML data returned but any call could also return an error which is a different structure. I think I read that I just need to create a data contract and it will be automagically deserialized, but I don't understand how to handle an error with a different structure that can't be deserialized with the same data contract. Is there a better way? Any help would be appreciated. Cheers.
