Showing posts with label REST Services. Show all posts
Showing posts with label REST Services. Show all posts

Tuesday, July 26, 2016

simple json call from c#

string URL = "http://www.blah.com/";
                    string urlParameters = “?v=1”;
                   

                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri(URL);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    HttpResponseMessage response = client.GetAsync(urlParameters).Result; 
                    if (response.IsSuccessStatusCode)
                    {
                        string dataObjects = response.Content.ReadAsStringAsync().Result;
                        var jss = new JavaScriptSerializer();
                        var dict = jss.Deserialize<Dictionary<string, dynamic>>(dataObjects);

                        foreach (Dictionary<string, object> x in dict["items"])

                        {

Thursday, September 17, 2015

http 404 error on wcf rest service httpget

i was getting because of the length of the querystring

Wednesday, May 13, 2015

Friday, May 2, 2014

REST Clients

I had a situation where I needed to pass security in  a HTTP header - Postman worked while SOAPUI didn't

Friday, April 11, 2014

rest service working on local but not on server

may just need a bindingConfiguration that handles https

<security mode="Transport">

WebHost failed to process a request- specifies multiple request body parameters to be serialized without any wrapper elements.

instead of changing the code i changed the behavior from webHttp to enableWebScript

Wednesday, April 9, 2014

Endpoints using 'UriTemplate' cannot be used with 'System.ServiceModel.Description.WebScriptEnablingBehavior'.

change behaviours

400 Bad Request

will happen when you call a REST service using the wrong address (the address behavior that is not rest)


Internet Explorer cannot display the webpage

Tuesday, August 6, 2013

Easy way to test WCF and REST services - use WebServiceHost class

  static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/"));
            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "");
                host.Open();
                using (ChannelFactory<IService> cf = new ChannelFactory<IService>(new BasicHttpBinding(), "http://localhost:8000"))
                {
                   // cf.Endpoint.Behaviors.Add(new bas WebHttpBehavior());
                    IService channel = cf.CreateChannel();
                    herby h = channel.getHerby();
                    Console.WriteLine("   i: {0}", h.i );
                    Console.WriteLine("   s: {0}", h.s);
                    Console.WriteLine("");

                    Boris b = channel.getBoris();
                    Console.WriteLine("   i: {0}", h.i);
                    Console.WriteLine("   s: {0}", h.s);
                    Console.WriteLine("");
                }
                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();
              
                host.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
        }