----------------------------------------------------------- New Message on BDOTNET
----------------------------------------------------------- From: Nasha Message 1 in Discussion Hey Group,<o:p></o:p> <o:p></o:p> Today we will look how we can access web services with HTTP-GET and HTTP-POST protocols. <o:p></o:p> <o:p></o:p> .Net Framework 1.0 had all the three protocols i.e. HTTP-POST,HTTP-GET AND HTTP-SOAP enabled by default. But in version 1.1 only HTTP-SOAP is enabled by default. Hence if you want to access the web service my HTTP-POST or GET then you will have to enable it explicitly.<o:p></o:p> <o:p></o:p> Since HTTP-POST is not enabled by default in .Net framework 1.1 to test web service on the local machine there is a new protocol that has been added i.e. HTTPPOSTLOCALHOST. It is because of this protocol that while testing a web service you are able to view a test form on your local machine and not on a remote computer. <o:p></o:p> Let us check out each of these protocols individually: -<o:p></o:p> <o:p></o:p> HTTPPOSTLOCALHOST: - This is enabled by default in .Net Framework version 1.1. Hence if you access your website as http://localhost you will get the test form but if you test the same web service with http://<name of your computer> from some other computer than the test form will not be displayed.<o:p></o:p> <o:p></o:p> e.g. Try and access our trigonometry web service from your machine and then access it from any other machine. You will notice that the test form will not be displayed.<o:p></o:p> <o:p></o:p> Before we look at HTTP-POST and HTTP-GET we need to checkout DefaultWsdlHelpGenerator.aspx.<o:p></o:p> <o:p></o:p> DefaultWsdlHelpGenerator.aspx is the default wsdl help file located at <drive>:\WINNT\Microsoft.NET\Framework\v1.1.4322\CONFIG.<o:p></o:p> <o:p></o:p> Open DefaultWsdlHelpGenerator.aspx and checkout showPost flag. <o:p></o:p> bool showPost = true; // search for this<o:p></o:p> <o:p></o:p> Depending the value of showPost flag HTTP-GET or HTTP-POST protocol is used.Set its value to true if you want to see a POST test form and false to view a GET test form.<o:p></o:p> <o:p></o:p> Along with this you will have to include the appropriate protocols in the web services tag in Web.config.<o:p></o:p> <o:p></o:p> HTTP-POST: - To enable our web service with HTTP-POST we will have to make the following changes.<o:p></o:p> <o:p></o:p> 1. Open the web.config and add the <webServices> tag under <system.web> as follows to enable the HTTP-POST protocol.<o:p></o:p> <o:p></o:p> <webServices> <protocols> <add name="HttpPost"/> </protocols> </webServices><o:p></o:p> <o:p></o:p> 2. Open DefaultWsdlHelpGenerator.aspx and set the value of showPost to true. By default it is set to true. 3. Run the web service and checkout the HTTP-POST form. 4. On execution you will see the xml output of your webservice. Checkout the URL of output in the browser it will not show any querystring parameters.<o:p></o:p> <o:p></o:p> http://namrathas/Trigonometery/MyService.asmx/CoSine<o:p></o:p> <o:p></o:p> 5. Execute your web service from some other computer and you will be able to view HTTP-POST test form.<o:p></o:p> <o:p></o:p> HTTP-GET: - To enable our web service with HTTP-GET we will have to make the following changes.<o:p></o:p> <o:p></o:p> 1. Open the web.config and add <add name="HttpGet"/> to protocols tage s follows to enable our webservice with HTTP-GET protocol also.<o:p></o:p> <o:p></o:p> <webServices> <protocols> <add name="HttpPost"/> <add name="HttpGet"/> </protocols> </webServices><o:p></o:p> <o:p></o:p> 2. Open DefaultWsdlHelpGenerator.aspx and set the value of showPost to false. So now HTTP-POST form will be displayed. All the parameters will be passed as querystring.<o:p></o:p> <o:p></o:p> http://namratas/Trigo/MyService.asmx/CoSine?angel=5<o:p></o:p> <o:p></o:p> 3. Run the web service and checkout the HTTP-GET form. Its looks the same as HTTP-POST form. You will notice the difference on execution. 4. Execute the web service and you will see the xml output of your webservice. Checkout the URL of output in the browser it will show query string parameters passed to the web method.<o:p></o:p> <o:p></o:p> HTTP-SOAP: - Whenever our webservice is accessed from any application HTTP-SOAP protocol is used. HTTP-SOAP is enabled by default. We will look in to more details of HTTP-SOAP when we look into consuming webservices.<o:p></o:p> <o:p></o:p> Hence if want our webservice to be enabled for all the four protocols we need to add them in the <protocols> tag.<o:p></o:p> <o:p></o:p> <webServices> <protocols> <add name="HttpPost"/> <add name="HttpGet"/> <add name="HttpSoap"/> <add name="HttpPostLocalhost"/> </protocols> </webServices><o:p></o:p> If you have any queries related to this pls post them in the group and mail it to me at my gmail account. -- Please post your queries and comments for my articles in the usergroup for the benefit of all. I hope this step from my end is helpful to all of us. Regards, Namratha (Nasha) ----------------------------------------------------------- To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings. http://groups.msn.com/BDotNet/_emailsettings.msnw Need help? If you've forgotten your password, please go to Passport Member Services. http://groups.msn.com/_passportredir.msnw?ppmprop=help For other questions or feedback, go to our Contact Us page. http://groups.msn.com/contact If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list. mailto:[EMAIL PROTECTED]
