WCF REST Client Console App

The following is the console client, which consumes Rest Service:
 
using System.Net;
using System.IO;
 
static void RestCall()
        {
            string baseUri = http://localhost:33987/MyService.svc/GetData/10;
            HttpWebRequest req = WebRequest.Create(baseUri) as HttpWebRequest;
            HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
            var response = resp.GetResponseStream();
            try
            {
                StreamReader streamReader = new StreamReader(response, true);
                try
                {
                    var target = streamReader.ReadToEnd();
                    Console.WriteLine(target);
                }
                finally
                {
                    streamReader.Close();
                }
            }
            finally
            {
                response.Close();
            }
        }

App.Config Entries:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>     
    <system.serviceModel>
        <bindings>
            <webHttpBinding>
                <binding name="webHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />                       
                    </security>
                </binding>
            </webHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:33987/MyService1.svc" binding="webHttpBinding"
bindingConfiguration="webHttpBinding_IService1" contract="MyServiceNameSpace.IService1"
                name="webHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

Another Url to see more clients with Post/Put/Delete methods:
http://www.codeproject.com/Articles/386956/RestFul-WCF-JSON-Service-with-client-and-on-Mozill

Comments

Popular posts from this blog

Windows Azure Package Build Error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resource ID : 1. The request limit for the database is 180 and has been reached.

How to get Client's Location using IPAddress