invoke webmethod using System.Net.WebRequest

invoke webmethod using System.Net.WebRequest

Page 1 of 1

3 Replies - 14079 Views - Last Post: 02 December 2007 - 11:27 PM Rate Topic: -----

#1 veeruu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 07

invoke webmethod using System.Net.WebRequest

Post icon  Posted 30 November 2007 - 12:19 AM

Hi,
i have implemeted the following functionality for WebApplication. And in the same way im looking to implement for a Webservice, but how to call webmethod which takes request and sends response back (public string ReceiveRequestMessage(string RequestXML)) by using this approach.


[b]Sample Code of WebApp [/b] :

			   WebRequest req = null;
			   string uri = "http://localhost/webApp/webpage.aspx";
				req = WebRequest.Create(uri);
				req.Method = "POST";		// Post method
				req.ContentType = "text/xml";	 // content type
				// Wrap the request stream with a text-based writer
				using (StreamWriter writer = new StreamWriter(req.GetRequestStream()))
				{
					writer.WriteLine(request);
				}

				//Get the Response Stream from the URL 
				 WebResponse response = req.GetResponse();




Its doing HTTP Post to a Web application, and functionalitiy is in Page load so im getting the response.But in Webservice i placed the functiuiolity in a webMethod.im following

http://www.hanselman...77-42cd4fead8db


but i dont know how to invoke that webmethod.
Pleaes help mee........

Thanks,
Veera

Is This A Good Question/Topic? 0
  • +

Replies To: invoke webmethod using System.Net.WebRequest

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: invoke webmethod using System.Net.WebRequest

Posted 30 November 2007 - 01:05 AM

So you actually created the Web Service and now you want to consume it, correct?

If so, then add it too your solution (right click on project and select "Add Web Reference"), give it the address of your web service and then create an object of that service. Then you will have access to the Web Method.

Is that what you are looking for?
Was This Post Helpful? 0
  • +
  • -

#3 veeruu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 07

Re: invoke webmethod using System.Net.WebRequest

Posted 02 December 2007 - 10:11 PM

hello jayman9,

No .. i know the approch what you said. But im looking for the approch wat i mentioned above. using System.net.WebResponse

thanks,
veera
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: invoke webmethod using System.Net.WebRequest

Posted 02 December 2007 - 11:27 PM

Are you sure you created a Web Service? Because the URL you are using is for an ASP.NET page, not a web service. A web service ends with an .ASMX extension.

Here is an example of a URL for a web service.
http://localhost/Exh...merService.asmx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1