mark smith
mark smith

Reputation: 20907

Consuming WCF Rest services with visual studio 2010?

I am used to using soap services where you add a service reference and it creates strong types classes (return types) of each method..

Of course REST doesn't work like this

How do i consume a WCF REST Service?

Is there no way to use strongly typed classes for the return types?

I am using Visual Studio 2010 specifically

Any ideas or thoughts really appreciated

Thanks in advance

Upvotes: 2

Views: 7277

Answers (2)

Ranjeet SIngh
Ranjeet SIngh

Reputation: 673

        // It is used to call the webservice url
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://careernet.localhost/rep-details/report_details/retrieves");
        request.Method = "POST";
        request.ContentType = "application/json";
        request.Accept = "application/json";

        try
        {
            WebResponse response = request.GetResponse();

            Stream responseStream = response.GetResponseStream();

           // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(responseStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // ...

I hope it will work for you.

Upvotes: 0

larsw
larsw

Reputation: 3830

See Is there a WCF Rest C# Client Generation Tool?. If you own both the service and the client, you can reuse the contracts and instantiate an client channel with WebChannelFactory.

Upvotes: 1

Related Questions