<p>In C#, if I need to open an HTTP connection, download XML and get one value from the result, how would I do that?</p>

<p>For consistency, imagine the webservice is at www.webservice.com and that if you pass it the POST argument fXML=1 it gives you back </p>

<pre><code>&lt;xml&gt;&lt;somekey&gt;somevalue&lt;/somekey&gt;&lt;/xml&gt;
</code></pre>

<p>I'd like it to spit out "somevalue".</p>

[{'answer_id': 51136, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 2, 'selected': False, 'text': '<p>I think it will be useful to read this first:</p>\n\n<p><a href="https://web.archive.org/web/20211020134836/https://aspnet.4guysfromrolla.com/articles/062602-1.aspx" rel="nofollow noreferrer">Creating and Consuming a Web Service</a> (in .NET)</p>\n\n<p>This is a series of tutorials of how web services are used in .NET, including how XML input is used (deserialization).</p>\n'}, {'answer_id': 51143, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 2, 'selected': False, 'text': '<p>You can use something like that:</p>\n\n<pre><code>var client = new WebClient();\nvar response = client.UploadValues("www.webservice.com", "POST", new NameValueCollection {{"fXML", "1"}});\nusing (var reader = new StringReader(Encoding.UTF8.GetString(response)))\n{\n    var xml = XElement.Load(reader);\n    var value = xml.Element("somekey").Value;\n    Console.WriteLine("Some value: " + value);                \n}\n</code></pre>\n\n<p>Note I didn\'t have a chance to test this code, but it should work :)</p>\n'}, {'answer_id': 51225, 'author': 'travis', 'author_id': 1414, 'author_profile': 'https://Stackoverflow.com/users/1414', 'pm_score': 3, 'selected': True, 'text': '<p>I use this code and it works great:</p>\n\n<pre><code>System.Xml.XmlDocument xd = new System.Xml.XmlDocument;\nxd.Load("http://www.webservice.com/webservice?fXML=1");\nstring xPath = "/xml/somekey";\n// this node\'s inner text contains "somevalue"\nreturn xd.SelectSingleNode(xPath).InnerText;\n</code></pre>\n\n<hr>\n\n<p>EDIT: I just realized you\'re talking about a webservice and not just plain XML. In your Visual Studio Solution, try right clicking on References in Solution Explorer and choose "Add a Web Reference". A dialog will appear asking for a URL, you can just paste it in: "<a href="http://www.webservice.com/webservice.asmx" rel="nofollow noreferrer">http://www.webservice.com/webservice.asmx</a>". VS will autogenerate all the helpers you need. Then you can just call:</p>\n\n<pre><code>com.webservice.www.WebService ws = new com.webservice.www.WebService();\n// this assumes your web method takes in the fXML as an integer attribute\nreturn ws.SomeWebMethod(1);\n</code></pre>\n'}, {'answer_id': 51383, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 0, 'selected': False, 'text': '<p>It may also be worth adding that if you need to specifically use POST rather than SOAP then you can configure the web service to receive POST calls:</p>\n\n<p>Check out the page on MSDN:\n<a href="http://msdn.microsoft.com/en-us/library/aa719747(VS.71).aspx" rel="nofollow noreferrer">Configuration Options for XML Web Services Created Using ASP.NET</a></p>\n'}]
['https://Stackoverflow.com/questions/51129', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/245/']