For my application, I'm currently using a webservice to retrieve some information I need in XML format. The way I'm doing it now is via a HTTP web request, so the code looks something like this:
serviceURL = "http://longurl/webservice.ashx?apikey=key&action=getDetail&id=ID";
HttpWReq = (HttpWebRequest)WebRequest.Create(serviceURL);
HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
dataXML.Load(HttpWResp.GetResponseStream());
I feel that including the entire URL inside my code looks really clunky, so I've thought of adding the web service as a web reference. However, I came across this error when trying to add the web reference:
The document at the url longurl/webservice.ashx was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'DISCO Document' is 'Discovery document at the URL longurl/webservice.ashx could not be found.'. - The document format is not recognized.
- Report from 'WSDL Document' is 'There is an error in XML document (2, 2).'. - was not expected.
- Report from 'XML Schema' is 'The root element of a W3C XML Schema should be and its namespace should be ''.'.
Am I missing any steps that I had to do before attempting to add the web service? Or is this a problem with the web service itself?
I'd also appreciate any advice on alternative methods to code this a bit more elegantly. Thanks.