/ Published in: C#
                    
                                        Basic example of calling a web service from code using GET. You can pass parameters in as query vars.
Assumes return type of service is "String". Example return xml:
    
US
@SNIPPLR TEAM: Please let me put xml attributes in code sections in comments!
                Assumes return type of service is "String". Example return xml:
US
@SNIPPLR TEAM: Please let me put xml attributes in code sections in comments!
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
 public string getServiceResult(string serviceUrl) { HttpWebRequest HttpWReq; HttpWebResponse HttpWResp; HttpWReq = (HttpWebRequest)WebRequest.Create(serviceUrl); HttpWReq.Method = "GET"; HttpWResp = (HttpWebResponse)HttpWReq.GetResponse(); if (HttpWResp.StatusCode == HttpStatusCode.OK) { //Consume webservice with basic XML reading, assumes it returns (one) string XmlReader reader = XmlReader.Create(HttpWResp.GetResponseStream()); while (reader.Read()) { reader.MoveToFirstAttribute(); if (reader.NodeType == XmlNodeType.Text) { return reader.Value; } } return String.Empty; } else { } }
Comments
                    Subscribe to comments
                
                