Question

Being new to ASP.NET and the fun that comes along with statelessness, I have been spending a lot of time wrapping my head around the concepts. Having said that....

I am dealing with a third party API that uses restful webservices to change/view data. First I found out how to call a webservice in asp.net, and then from viewing the APIs documentation I saw that to get data you do this:

enter image description here

So I wrote the following to look at a space's feature (objects in their database):

request = WebRequest.Create(ReqURL + query) as HttpWebRequest;

        if (DidAuthenticate(query))
        {
            try
            {
                //It will 404 if that space does not contain any custom attributes
                using (response = request.GetResponse() as HttpWebResponse)
                {
                    //Get the steam of the XML
                    StreamReader reader = new StreamReader(response.GetResponseStream());

                    //Put the XML in a document
                    XmlDocument doc = new XmlDocument();
                    doc.Load(reader);

                    //Grab all the space nodes
                    XmlNodeList featuresList = doc.GetElementsByTagName("r25:feature");

                    if (featuresList.Count > 0)
                    {
                        //Get all the info from the child nodes of the space node
                        foreach (XmlNode node in featuresList)
                        {
                            XmlNodeList childInfo = node.ChildNodes;

                            //The order never changes..i.e. the first index is always the id, 2nd is name, 3rd is quantity
                            Feature aFeature = new Feature(childInfo[ID].InnerText,
                                childInfo[NAME].InnerText, Int16.Parse(childInfo[QUANTITY].InnerText));

                            //Return all of the features
                            features.Add(aFeature);

                        }

                    }

                }
            }
            catch (WebException)
            {
                throw new WebException();
            }

And that worked great, I now had all the information I needed. Now, I am trying to learn how to send back information via their webservices to change information, and this is where I am struggling. I have seen that they use "PUT" to do so, so I tried to find tutorials that use http put in asp.net but I didn't find exactly what I was needing due to my ignorance on the topic or not fully understanding the results.

Here is what the API documentation says on manipulating information:

enter image description here

So can someone provide a quick code sample/psuedo code showing how I am to use this webservice? GET is just fine, but I am not sure where to start with PUT.

Was it helpful?

Solution

you can set the put in the request.Method = "PUT" and call the URL . Just try . PUT is similar to POST but rather than creating new entry its update the entry based on the Id that you send as part of the URL. This blog will help you to code : http://vinothnat.blogspot.in/2007/09/httpwebrequest-using-put-method.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top