Search code examples
c#.netweb-serviceshttpwebrequest

HttpWebRequest vs Add service reference


Can somebody please define the difference between HttpWebRequest and Adding service reference when using web services? Also what is the best approach.


Solution

  • Add reference can only be done with web service URLs (.net amsx services, wcf services, and other SOAP based services like in java,php or ruby etc). Adding a reference generates stub which contains all the classes necessary for calling web services. It includes all object types that are passed as parameters or returned from web methods.

    On the other hand HttpWebRequest can be used not only to call webservices but simple aspx pages, HTML pages or any HTTP or HTTPS based urls. Its just like hitting a URL in browser.